• 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/compiler/nearbyIdenticalGenericLambdasAssignable.ts ===
20declare function AssertType(value:any, type:string):void;
21declare const fA: <T>() => { v: T };
22AssertType(fA, "<T>() => { v: T; }");
23AssertType(v, "T");
24
25const fB = <T>() => {
26AssertType(fB, "<T>() => { v: T; }");
27AssertType(<T>() => {    return { v: '' as any as T };}, "<T>() => { v: T; }");
28
29AssertType({ v: '' as any as T }, "{ v: T; }");
30AssertType(v, "T");
31AssertType('' as any as T, "T");
32AssertType('' as any, "any");
33AssertType('', "string");
34    return { v: '' as any as T };
35
36};
37const fC = <T>() => {
38AssertType(fC, "<T>() => { v: T; }");
39AssertType(<T>() => {    return {} as any as { v: T };}, "<T>() => { v: T; }");
40
41AssertType({} as any as { v: T }, "{ v: T; }");
42AssertType({} as any, "any");
43AssertType({}, "{}");
44AssertType(v, "T");
45    return {} as any as { v: T };
46
47};
48
49// Hover display is identical on all of these
50type TA = typeof fA;
51type TB = typeof fB;
52type TC = typeof fC;
53type TL = <T>() => { v: T };
54
55declare function accA(x: TA): void;
56declare function accB(x: TB): void;
57declare function accC(x: TC): void;
58declare function accL(x: TL): void;
59
60// These should all be OK, every type is identical
61accA(fA); accA(fB); accA(fC);
62AssertType(accA(fA), "void");
63AssertType(accA, "(<T>() => { v: T; }) => void");
64AssertType(fA, "<T>() => { v: T; }");
65AssertType(accA(fB), "void");
66AssertType(accA, "(<T>() => { v: T; }) => void");
67AssertType(fB, "<T>() => { v: T; }");
68AssertType(accA(fC), "void");
69AssertType(accA, "(<T>() => { v: T; }) => void");
70AssertType(fC, "<T>() => { v: T; }");
71
72//             ~~ previously an error
73accB(fA); accB(fB); accB(fC);
74AssertType(accB(fA), "void");
75AssertType(accB, "(<T>() => { v: T; }) => void");
76AssertType(fA, "<T>() => { v: T; }");
77AssertType(accB(fB), "void");
78AssertType(accB, "(<T>() => { v: T; }) => void");
79AssertType(fB, "<T>() => { v: T; }");
80AssertType(accB(fC), "void");
81AssertType(accB, "(<T>() => { v: T; }) => void");
82AssertType(fC, "<T>() => { v: T; }");
83
84//             OK
85accC(fA); accC(fB); accC(fC);
86AssertType(accC(fA), "void");
87AssertType(accC, "(<T>() => { v: T; }) => void");
88AssertType(fA, "<T>() => { v: T; }");
89AssertType(accC(fB), "void");
90AssertType(accC, "(<T>() => { v: T; }) => void");
91AssertType(fB, "<T>() => { v: T; }");
92AssertType(accC(fC), "void");
93AssertType(accC, "(<T>() => { v: T; }) => void");
94AssertType(fC, "<T>() => { v: T; }");
95
96//             ~~ previously an error
97accL(fA); accL(fB); accL(fC);
98AssertType(accL(fA), "void");
99AssertType(accL, "(TL) => void");
100AssertType(fA, "<T>() => { v: T; }");
101AssertType(accL(fB), "void");
102AssertType(accL, "(TL) => void");
103AssertType(fB, "<T>() => { v: T; }");
104AssertType(accL(fC), "void");
105AssertType(accL, "(TL) => void");
106AssertType(fC, "<T>() => { v: T; }");
107
108//             ~~ previously an error
109
110