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/objectTypesIdentityWithStringIndexers.ts === 20declare function AssertType(value:any, type:string):void; 21// object types are identical structurally 22 23class A { 24 [x: string]: string; 25} 26 27class B { 28 [x: string]: string; 29} 30 31class C<T> { 32 [x: string]: T; 33} 34 35interface I { 36 [x: string]: string; 37} 38 39class PA extends A { 40} 41 42class PB extends B { 43} 44 45let a: { 46AssertType(a, "{ [string]: string; }"); 47 48 [x: string]: string; 49AssertType(x, "string"); 50} 51let b: { [x: string]: string; } = { foo: '' }; 52AssertType(b, "{ [string]: string; }"); 53AssertType(x, "string"); 54AssertType({ foo: '' }, "{ foo: string; }"); 55AssertType(foo, "string"); 56AssertType('', "string"); 57 58function foo1(x: A); 59function foo1(x: A); // error 60function foo1(x: any) { } 61 62function foo1b(x: B); 63function foo1b(x: B); // error 64function foo1b(x: any) { } 65 66function foo1c(x: C<string>); 67function foo1c(x: C<string>); // error 68function foo1c(x: any) { } 69 70function foo2(x: I); 71function foo2(x: I); // error 72function foo2(x: any) { } 73 74function foo3(x: typeof a); 75function foo3(x: typeof a); // error 76function foo3(x: any) { } 77 78function foo4(x: typeof b); 79function foo4(x: typeof b); // error 80function foo4(x: any) { } 81 82function foo5(x: A); 83function foo5(x: B); // error 84function foo5(x: any) { } 85 86function foo5b(x: A); 87function foo5b(x: C<string>); // error 88function foo5b(x: any) { } 89 90function foo5c(x: A); 91function foo5c(x: PA); // error 92function foo5c(x: any) { } 93 94function foo5d(x: A); 95function foo5d(x: PB); // error 96function foo5d(x: any) { } 97 98function foo6(x: A); 99function foo6(x: I); // error 100function foo6(x: any) { } 101 102function foo7(x: A); 103function foo7(x: typeof a); // error 104function foo7(x: any) { } 105 106function foo8(x: B); 107function foo8(x: I); // error 108function foo8(x: any) { } 109 110function foo9(x: B); 111function foo9(x: C<string>); // error 112function foo9(x: any) { } 113 114function foo10(x: B); 115function foo10(x: typeof a); // error 116function foo10(x: any) { } 117 118function foo11(x: B); 119function foo11(x: typeof b); // error 120function foo11(x: any) { } 121 122function foo11b(x: B); 123function foo11b(x: PA); // error 124function foo11b(x: any) { } 125 126function foo11c(x: B); 127function foo11c(x: PB); // error 128function foo11c(x: any) { } 129 130function foo12(x: I); 131function foo12(x: C<string>); // error 132function foo12(x: any) { } 133 134function foo13(x: I); 135function foo13(x: typeof a); // error 136function foo13(x: any) { } 137 138function foo14(x: I); 139function foo14(x: typeof b); // error 140function foo14(x: any) { } 141 142function foo15(x: I); 143function foo15(x: PA); // error 144function foo15(x: any) { } 145 146function foo16(x: I); 147function foo16(x: PB); // error 148function foo16(x: any) { } 149 150 151 152