• 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/subtypesAndSuperTypes/subtypingWithConstructSignatures3.ts ===
20declare function AssertType(value:any, type:string):void;
21
22// checking subtype relations for function types as it relates to contextual signature instantiation
23// error cases, so function calls will all result in 'any'
24
25module Errors {
26    class Base { foo: string; }
27    class Derived extends Base { bar: string; }
28    class Derived2 extends Derived { baz: string; }
29    class OtherDerived extends Base { bing: string; }
30
31    declare function foo2(a2: new (x: number) => string[]): typeof a2;
32    declare function foo2(a2: any): any;
33
34    declare function foo7(a2: new (x: new (arg: Base) => Derived) => new (r: Base) => Derived2): typeof a2;
35    declare function foo7(a2: any): any;
36
37    declare function foo8(a2: new (x: new (arg: Base) => Derived, y: new (arg2: Base) => Derived) => new (r: Base) => Derived): typeof a2;
38    declare function foo8(a2: any): any;
39
40    declare function foo10(a2: new (...x: Base[]) => Base): typeof a2;
41    declare function foo10(a2: any): any;
42
43    declare function foo11(a2: new (x: { foo: string }, y: { foo: string; bar: string }) => Base): typeof a2;
44    declare function foo11(a2: any): any;
45
46    declare function foo12(a2: new (x: Array<Base>, y: Array<Derived2>) => Array<Derived>): typeof a2;
47    declare function foo12(a2: any): any;
48
49    declare function foo15(a2: new (x: { a: string; b: number }) => number): typeof a2;
50    declare function foo15(a2: any): any;
51
52    declare function foo16(a2: {
53        // type of parameter is overload set which means we can't do inference based on this type
54        new (x: {
55            new (a: number): number;
56            new (a?: number): number;
57        }): number[];
58        new (x: {
59            new (a: boolean): boolean;
60            new (a?: boolean): boolean;
61        }): boolean[];
62    }): typeof a2;
63    declare function foo16(a2: any): any;
64
65    declare function foo17(a2: {
66        new (x: {
67            new <T extends Derived>(a: T): T;
68            new <T extends Base>(a: T): T;
69        }): any[];
70        new (x: {
71            new <T extends Derived2>(a: T): T;
72            new <T extends Base>(a: T): T;
73        }): any[];
74    }): typeof a2;
75    declare function foo17(a2: any): any;
76
77    let r1arg1: new <T, U>(x: T) => U[];
78    let r1arg2: new (x: number) => string[];
79    let r1 = foo2(r1arg1); // any
80    let r1a = [r1arg2, r1arg1];
81    let r1b = [r1arg1, r1arg2];
82
83    let r2arg1: new <T extends Base, U extends Derived, V extends Derived2>(x: new (arg: T) => U) => new (r: T) => V;
84    let r2arg2: new (x: new (arg: Base) => Derived) => new (r: Base) => Derived2;
85    let r2 = foo7(r2arg1); // any
86    let r2a = [r2arg2, r2arg1];
87    let r2b = [r2arg1, r2arg2];
88
89    let r3arg1: new <T extends Base, U extends Derived>(x: new (arg: T) => U, y: (arg2: { foo: number; }) => U) => new (r: T) => U;
90    let r3arg2: new (x: (arg: Base) => Derived, y: new (arg2: Base) => Derived) => new (r: Base) => Derived;
91    let r3 = foo8(r3arg1); // any
92    let r3a = [r3arg2, r3arg1];
93    let r3b = [r3arg1, r3arg2];
94
95    let r4arg1: new <T extends Derived>(...x: T[]) => T;
96    let r4arg2: new (...x: Base[]) => Base;
97    let r4 = foo10(r4arg1); // any
98    let r4a = [r4arg2, r4arg1];
99    let r4b = [r4arg1, r4arg2];
100
101    let r5arg1: new <T extends Derived>(x: T, y: T) => T;
102    let r5arg2: new (x: { foo: string }, y: { foo: string; bar: string }) => Base;
103    let r5 = foo11(r5arg1); // any
104    let r5a = [r5arg2, r5arg1];
105    let r5b = [r5arg1, r5arg2];
106
107    let r6arg1: new (x: Array<Base>, y: Array<Derived2>) => Array<Derived>;
108    let r6arg2: new <T extends Array<Derived2>>(x: Array<Base>, y: Array<Base>) => T;
109    let r6 = foo12(r6arg1); // new (x: Array<Base>, y: Array<Derived2>) => Array<Derived>
110    let r6a = [r6arg2, r6arg1];
111    let r6b = [r6arg1, r6arg2];
112
113    let r7arg1: new <T>(x: { a: T; b: T }) => T;
114    let r7arg2: new (x: { a: string; b: number }) => number;
115    let r7 = foo15(r7arg1); // (x: { a: string; b: number }) => number): number;
116    let r7a = [r7arg2, r7arg1];
117    let r7b = [r7arg1, r7arg2];
118
119    let r7arg3: new <T extends Base>(x: { a: T; b: T }) => number;
120    let r7c = foo15(r7arg3); // any
121    let r7d = [r7arg2, r7arg3];
122    let r7e = [r7arg3, r7arg2];
123
124    let r8arg: new <T>(x: new (a: T) => T) => T[];
125    let r8 = foo16(r8arg); // any
126
127    let r9arg: new <T>(x: new (a: T) => T) => any[];
128    let r9 = foo17(r9arg); // // (x: { <T extends Derived >(a: T): T; <T extends Base >(a: T): T; }): any[]; (x: { <T extends Derived2>(a: T): T; <T extends Base>(a: T): T; }): any[];
129}
130
131module WithGenericSignaturesInBaseType {
132    declare function foo2(a2: new <T>(x: T) => T[]): typeof a2;
133    declare function foo2(a2: any): any;
134    let r2arg2: new <T>(x: T) => string[];
135    let r2 = foo2(r2arg2); // <T>(x:T) => T[] since we can infer from generic signatures now
136
137    declare function foo3(a2: new <T>(x: T) => string[]): typeof a2;
138    declare function foo3(a2: any): any;
139    let r3arg2: new <T>(x: T) => T[];
140    let r3 = foo3(r3arg2); // any
141}
142
143