• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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/objectTypesIdentityWithPublics.ts ===
20declare function AssertType(value:any, type:string):void;
21// object types are identical structurally
22
23class A {
24    public foo: string;
25}
26
27class B {
28    public foo: string;
29}
30
31class C<T> {
32    public 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 foo1(x: A);
52function foo1(x: A); // error
53function foo1(x: any) { }
54
55function foo1b(x: B);
56function foo1b(x: B); // error
57function foo1b(x: any) { }
58
59function foo1c(x: C<string>);
60function foo1c(x: C<string>); // error
61function foo1c(x: any) { }
62
63function foo2(x: I);
64function foo2(x: I); // error
65function foo2(x: any) { }
66
67function foo3(x: typeof a);
68function foo3(x: typeof a); // error
69function foo3(x: any) { }
70
71function foo4(x: typeof b);
72function foo4(x: typeof b); // error
73function foo4(x: any) { }
74
75function foo5(x: A);
76function foo5(x: B); // error
77function foo5(x: any) { }
78
79function foo5b(x: A);
80function foo5b(x: C<string>); // error
81function foo5b(x: any) { }
82
83function foo6(x: A);
84function foo6(x: I); // error
85function foo6(x: any) { }
86
87function foo7(x: A);
88function foo7(x: typeof a); // error
89function foo7(x: any) { }
90
91function foo8(x: B);
92function foo8(x: I); // error
93function foo8(x: any) { }
94
95function foo9(x: B);
96function foo9(x: C<string>); // error
97function foo9(x: any) { }
98
99function foo10(x: B);
100function foo10(x: typeof a); // error
101function foo10(x: any) { }
102
103function foo11(x: B);
104function foo11(x: typeof b); // error
105function foo11(x: any) { }
106
107function foo12(x: I);
108function foo12(x: C<string>); // error
109function foo12(x: any) { }
110
111function foo13(x: I);
112function foo13(x: typeof a); // error
113function foo13(x: any) { }
114
115function foo14(x: I);
116function foo14(x: typeof b); // error
117function foo14(x: any) { }
118
119