• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/*
2 * Copyright (c) 2023 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 *     http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16declare function AssertType(value:any, type:string):void;
17
18class C {
19    public x;
20    public b: string = '';
21    public c(): string {
22        AssertType('', "string");
23        return ''
24    }
25
26    public static e;
27    public static f() : string {
28        AssertType('', "string");
29        return ''
30    }
31}
32
33let c = new C();
34AssertType(c, "C");
35AssertType(new C(), "C");
36AssertType(C, "typeof C");
37
38let r1: string = c.x;
39AssertType(r1, "string");
40AssertType(c.x, "any");
41
42let tmp = "x";
43let value1: string = c[tmp]
44AssertType(c[tmp], "any");
45AssertType(value1, "string");
46
47let r3: string = c.b;
48AssertType(r3, "string");
49AssertType(c.b, "string");
50
51tmp = "b";
52let value2: string = c[tmp]
53AssertType(c[tmp], "string");
54AssertType(value2, "string");
55
56let r4: string = c.c();
57AssertType(r4, "string");
58AssertType(c.c(), "string");
59AssertType(c.c, "() => string");
60
61let r6: string = C.e;
62AssertType(r6, "string");
63AssertType(C.e, "any");
64
65tmp = "e";
66let value3: string = c[tmp]
67AssertType(c[tmp], "any");
68AssertType(value3, "string");
69
70let r7: string = C.f();
71AssertType(r7, "string");
72AssertType(C.f(), "string");
73AssertType(C.f, "() => string");