• 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/interfaces/interfaceDeclarations/interfaceWithPropertyOfEveryType.ts ===
20declare function AssertType(value:any, type:string):void;
21class C { foo: string; }
22function f1() { }
23module M {
24    export let y = 1;
25}
26enum E { A }
27
28interface Foo {
29    a: number;
30    b: string;
31    c: boolean;
32    d: any;
33    e: void;
34    f: number[];
35    g: Object;
36    h: (x: number) => number;
37    i: <T>(x: T) => T;
38    j: Foo;
39    k: C;
40    l: typeof f1;
41    m: typeof M;
42    n: {};
43    o: E;
44}
45
46let a: Foo = {
47AssertType(a, "Foo");
48AssertType({    a: 1,    b: '',    c: true,    d: {},    e: null ,    f: [1],    g: {},    h: (x: number) => 1,    i: <T>(x: T) => x,    j: <Foo>null,    k: new C(),    l: f1,    m: M,    n: {},    o: E.A}, "{ a: number; b: string; c: true; d: {}; e: null; f: number[]; g: {}; h: (number) => number; i: <T>(T) => T; j: Foo; k: C; l: () => void; m: typeof M; n: {}; o: E; }");
49
50    a: 1,
51AssertType(a, "number");
52AssertType(1, "int");
53
54    b: '',
55AssertType(b, "string");
56AssertType('', "string");
57
58    c: true,
59AssertType(c, "boolean");
60AssertType(true, "boolean");
61
62    d: {},
63AssertType(d, "{}");
64AssertType({}, "{}");
65
66    e: null ,
67AssertType(e, "null");
68AssertType(null, "null");
69
70    f: [1],
71AssertType(f, "number[]");
72AssertType([1], "number[]");
73AssertType(1, "int");
74
75    g: {},
76AssertType(g, "{}");
77AssertType({}, "{}");
78
79    h: (x: number) => 1,
80AssertType(h, "(number) => number");
81AssertType((x: number) => 1, "(number) => number");
82AssertType(x, "number");
83AssertType(1, "int");
84
85    i: <T>(x: T) => x,
86AssertType(i, "<T>(T) => T");
87AssertType(<T>(x: T) => x, "<T>(T) => T");
88AssertType(x, "T");
89AssertType(x, "T");
90
91    j: <Foo>null,
92AssertType(j, "Foo");
93AssertType(<Foo>null, "Foo");
94AssertType(null, "null");
95
96    k: new C(),
97AssertType(k, "C");
98AssertType(new C(), "C");
99AssertType(C, "typeof C");
100
101    l: f1,
102AssertType(l, "() => void");
103AssertType(f1, "() => void");
104
105    m: M,
106AssertType(m, "typeof M");
107AssertType(M, "typeof M");
108
109    n: {},
110AssertType(n, "{}");
111AssertType({}, "{}");
112
113    o: E.A
114AssertType(o, "E");
115AssertType(E.A, "E");
116}
117
118