• 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/specifyingTypes/typeLiterals/functionLiteralForOverloads2.ts ===
20declare function AssertType(value:any, type:string):void;
21// basic uses of function literals with constructor overloads
22
23class C {
24    constructor(x: string);
25    constructor(x: number);
26    constructor(x) { }
27}
28
29class D<T> {
30    constructor(x: string);
31    constructor(x: number);
32    constructor(x) { }
33}
34
35let f: {
36AssertType(f, "{ new (string): C; new (number): C; }");
37
38    new(x: string): C;
39AssertType(x, "string");
40
41    new(x: number): C;
42AssertType(x, "number");
43
44} = C;
45AssertType(C, "typeof C");
46
47let f2: {
48AssertType(f2, "{ new <T>(string): C; new <T>(number): C; }");
49
50    new<T>(x: string): C;
51AssertType(x, "string");
52
53    new<T>(x: number): C;
54AssertType(x, "number");
55
56} = C;
57AssertType(C, "typeof C");
58
59let f3: {
60AssertType(f3, "{ new <T>(string): D<T>; new <T>(number): D<T>; }");
61
62    new<T>(x: string): D<T>;
63AssertType(x, "string");
64
65    new<T>(x: number): D<T>;
66AssertType(x, "number");
67
68} = D;
69AssertType(D, "typeof D");
70
71
72