1/* 2* Copyright (c) Microsoft Corporation. All rights reserved. 3* Copyright (c) 2023 Huawei Device Co., Ltd. 4* Licensed under the Apache License, Version 2.0 (the "License"); 5* you may not use this file except in compliance with the License. 6* You may obtain a copy of the License at 7* 8* http://www.apache.org/licenses/LICENSE-2.0 9* 10* Unless required by applicable law or agreed to in writing, software 11* distributed under the License is distributed on an "AS IS" BASIS, 12* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13* See the License for the specific language governing permissions and 14* limitations under the License. 15* 16* This file has been modified by Huawei to verify type inference by adding verification statements. 17*/ 18 19// === tests/cases/conformance/types/typeRelationships/typeAndMemberIdentity/objectTypesIdentityWithOptionality.ts === 20declare function AssertType(value:any, type:string):void; 21// object types are identical structurally 22 23class A { 24 foo: string; 25} 26 27class B { 28 foo: string; 29} 30 31class C<T> { 32 foo: T; 33} 34 35interface I { 36 foo?: string; 37} 38 39let a: { foo?: string; 40AssertType(a, "{ foo?: string; }"); 41 42AssertType(foo, "string"); 43} 44 45let b = { foo: '' }; 46AssertType(b, "{ foo: string; }"); 47AssertType({ foo: '' }, "{ foo: string; }"); 48AssertType(foo, "string"); 49AssertType('', "string"); 50 51function foo2(x: I); 52function foo2(x: I); // error 53function foo2(x: any) { } 54 55function foo3(x: typeof a); 56function foo3(x: typeof a); // error 57function foo3(x: any) { } 58 59function foo6(x: A); 60function foo6(x: I); // ok 61function foo6(x: any) { } 62 63function foo7(x: A); 64function foo7(x: typeof a); // ok 65function foo7(x: any) { } 66 67function foo8(x: B); 68function foo8(x: I); // ok 69function foo8(x: any) { } 70 71function foo10(x: B); 72function foo10(x: typeof a); // ok 73function foo10(x: any) { } 74 75function foo12(x: I); 76function foo12(x: C<string>); // ok 77function foo12(x: any) { } 78 79function foo13(x: I); 80function foo13(x: typeof a); // error 81function foo13(x: any) { } 82 83function foo14(x: I); 84function foo14(x: typeof b); // ok 85function foo14(x: any) { } 86 87