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