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