• 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/typeInference/genericCallWithFunctionTypedArguments4.ts ===
20declare function AssertType(value:any, type:string):void;
21// No inference is made from function typed arguments which have multiple call signatures
22
23class C { foo: string }
24class D { bar: string }
25let a: {
26AssertType(a, "{ new (boolean): C; new (string): D; }");
27
28    new(x: boolean): C;
29AssertType(x, "boolean");
30
31    new(x: string): D;
32AssertType(x, "string");
33}
34
35function foo4<T, U>(cb: new(x: T) => U) {
36    let u: U;
37AssertType(u, "U");
38
39AssertType(u, "U");
40    return u;
41}
42
43let r = foo4(a); // T is {} (candidates boolean and string), U is {} (candidates C and D)
44AssertType(r, "D");
45AssertType(foo4(a), "D");
46AssertType(foo4, "<T, U>(new (T) => U) => U");
47AssertType(a, "{ new (boolean): C; new (string): D; }");
48
49let b: {
50AssertType(b, "{ new <T>(boolean): T; new <T>(T): any; }");
51
52    new<T>(x: boolean): T;
53AssertType(x, "boolean");
54
55    new<T>(x: T): any;
56AssertType(x, "T");
57}
58
59let r2 = foo4(b); // T is {} (candidates boolean and {}), U is any (candidates any and {})
60AssertType(r2, "any");
61AssertType(foo4(b), "any");
62AssertType(foo4, "<T, U>(new (T) => U) => U");
63AssertType(b, "{ new <T>(boolean): T; new <T>(T): any; }");
64
65
66