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