• 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/jsdoc/declarations/index.js ===
20declare function AssertType(value:any, type:string):void;
21export class A {}
22
23export class B {
24    static cat = "cat";
25}
26
27export class C {
28    static Cls = class {}
29}
30
31export class D {
32    /**
33     * @param {number} a
34     * @param {number} b
35     */
36    constructor(a, b) {}
37}
38
39/**
40 * @template T,U
41 */
42export class E {
43    /**
44     * @type {T & U}
45     */
46    field;
47
48    // @readonly is currently unsupported, it seems - included here just in case that changes
49    /**
50     * @type {T & U}
51     * @readonly
52     */
53    readonlyField;
54
55    initializedField = 12;
56
57    /**
58     * @
59return {U}
60     */
61    get f1() {
62AssertType((null), "any");
63return /** @type {*} */(null);
64
65AssertType(null, "null");
66}
67
68    /**
69     * @param {U} _p
70     */
71    set f1(_p) {}
72
73    /**
74     * @
75return {U}
76     */
77    get f2() {
78AssertType((null), "any");
79return /** @type {*} */(null);
80
81AssertType(null, "null");
82}
83
84    /**
85     * @param {U} _p
86     */
87    set f3(_p) {}
88
89    /**
90     * @param {T} a
91     * @param {U} b
92     */
93    constructor(a, b) {}
94
95
96    /**
97     * @type {string}
98     */
99    static staticField;
100
101    // @readonly is currently unsupported, it seems - included here just in case that changes
102    /**
103     * @type {string}
104     * @readonly
105     */
106    static staticReadonlyField;
107
108    static staticInitializedField = 12;
109
110    /**
111     * @
112return {string}
113     */
114    static get s1() {
115AssertType("", "string");
116return "";
117}
118
119    /**
120     * @param {string} _p
121     */
122    static set s1(_p) {}
123
124    /**
125     * @
126return {string}
127     */
128    static get s2() {
129AssertType("", "string");
130return "";
131}
132
133    /**
134     * @param {string} _p
135     */
136    static set s3(_p) {}
137}
138
139/**
140 * @template T,U
141 */
142export class F {
143    /**
144     * @type {T & U}
145     */
146    field;
147    /**
148     * @param {T} a
149     * @param {U} b
150     */
151    constructor(a, b) {}
152
153    /**
154     * @template A,B
155     * @param {A} a
156     * @param {B} b
157     */
158    static create(a, b) {
159AssertType(new F(a, b), "F<A, B>");
160return new F(a, b);
161
162AssertType(F, "typeof F");
163
164AssertType(a, "A");
165
166AssertType(b, "B");
167}
168}
169
170class G {}
171
172export { G };
173
174class HH {}
175
176export { HH as H };
177
178export class I {}
179export { I as II };
180
181export { J as JJ };
182export class J {}
183
184
185export class K {
186    constructor() {
187        this.p1 = 12;
188AssertType(this.p1 = 12, "int");
189AssertType(this.p1, "any");
190AssertType(this, "this");
191AssertType(12, "int");
192
193        this.p2 = "ok";
194AssertType(this.p2 = "ok", "string");
195AssertType(this.p2, "any");
196AssertType(this, "this");
197AssertType("ok", "string");
198    }
199
200    method() {
201AssertType(this.p1, "number");
202AssertType(this, "this");
203        return this.p1;
204    }
205}
206
207export class L extends K {}
208
209export class M extends null {
210    constructor() {
211        this.prop = 12;
212AssertType(this.prop = 12, "int");
213AssertType(this.prop, "any");
214AssertType(this, "this");
215AssertType(12, "int");
216    }
217}
218
219
220/**
221 * @template T
222 */
223export class N extends L {
224    /**
225     * @param {T} param
226     */
227    constructor(param) {
228        super();
229AssertType(super(), "void");
230AssertType(super, "typeof L");
231
232        this.another = param;
233AssertType(this.another = param, "T");
234AssertType(this.another, "any");
235AssertType(this, "this");
236AssertType(param, "T");
237    }
238}
239
240/**
241 * @template U
242 * @extends {N<U>}
243 */
244export class O extends N {
245    /**
246     * @param {U} param
247     */
248    constructor(param) {
249        super(param);
250AssertType(super(param), "void");
251AssertType(super, "typeof N");
252AssertType(param, "U");
253
254        this.another2 = param;
255AssertType(this.another2 = param, "U");
256AssertType(this.another2, "any");
257AssertType(this, "this");
258AssertType(param, "U");
259    }
260}
261
262let x = /** @type {*} */(null);
263AssertType(x, "any");
264AssertType((null), "any");
265AssertType(null, "null");
266
267export class VariableBase extends x {}
268
269export class HasStatics {
270    static staticMethod() {}
271}
272
273export class ExtendsStatics extends HasStatics {
274    static also() {}
275}
276
277
278