Skip to content

Commit 297ba1b

Browse files
Added tests for using type from assertion in declarations.
1 parent af0424c commit 297ba1b

7 files changed

+1316
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,273 @@
1+
//// [tests/cases/compiler/verbatim-declarations-assertions.ts] ////
2+
3+
//// [assertToTypeReferences.ts]
4+
type P = { } & { name: string }
5+
6+
export let vLet = null! as P
7+
export const vConst = null! as P
8+
9+
export function fn(p = null! as P) {}
10+
11+
export function fnWithRequiredDefaultParam(p = null! as P, req: number) {}
12+
13+
export class C {
14+
field = null! as P
15+
readonly roFiled = null! as P;
16+
method(p = null! as P) {}
17+
methodWithRequiredDefault(p = null! as P, req: number) {}
18+
methodWithRequiredDefault2(p = null! as P, req: number) {}
19+
20+
constructor(public ctorField = null! as P) {}
21+
}
22+
23+
export default null! as P;
24+
25+
//// [assertToTypeLiteral.ts]
26+
export let vLet = null! as {} & { name: string }
27+
export const vConst = null! as {} & { name: string }
28+
29+
export function fn(p = null! as {} & { name: string }) {}
30+
31+
export function fnWithRequiredDefaultParam(p = null! as {} & { name: string }, req: number) {}
32+
33+
export class C {
34+
field = null! as {} & { name: string }
35+
readonly roFiled = null! as {} & { name: string };
36+
method(p = null! as {} & { name: string }) {}
37+
methodWithRequiredDefault(p = null! as {} & { name: string }, req: number) {}
38+
39+
constructor(public ctorField = null! as {} & { name: string }) {}
40+
41+
get x() { return null! as {} & { name: string } }
42+
set x(v) { }
43+
}
44+
45+
export default null! as {} & { name: string }
46+
47+
48+
//// [assertToOtherTypes.ts]
49+
export const vNumberLiteral = null! as 1 | 1
50+
export const vStringLiteral = null! as "1" | "1"
51+
export const vLiteral = null! as "1" | "1"
52+
53+
type R = { foo: string }
54+
55+
export class C {
56+
// Can't know if references contain undefined, fall back to inference
57+
tsResolve? = null! as R | R;
58+
tsResolve2? = null! as R | R | string;
59+
// Simple type. we can add undefined
60+
reuseType? = null! as ((p: R) => void) | string | string;
61+
reuseType2? = null! as (new (p: R) => R) | string | string;
62+
reuseType3? = null! as string | number | bigint | symbol | unknown | any | never | symbol;
63+
reuseType4? = null! as [R, R, R] | [R, R, R];
64+
reuseType5? = null! as R[] | R[];
65+
reuseType6? = null! as 1 | "2" | 1n | 1n;
66+
reuseType7? = null! as `A` | `A`;
67+
reuseType8? = null! as `${string}-ok` | `${string}-ok`;
68+
reuseType9? = null! as this | this;
69+
}
70+
71+
//// [assertToTypeReferences.js]
72+
"use strict";
73+
Object.defineProperty(exports, "__esModule", { value: true });
74+
exports.C = exports.fnWithRequiredDefaultParam = exports.fn = exports.vConst = exports.vLet = void 0;
75+
exports.vLet = null;
76+
exports.vConst = null;
77+
function fn(p) {
78+
if (p === void 0) { p = null; }
79+
}
80+
exports.fn = fn;
81+
function fnWithRequiredDefaultParam(p, req) {
82+
if (p === void 0) { p = null; }
83+
}
84+
exports.fnWithRequiredDefaultParam = fnWithRequiredDefaultParam;
85+
var C = /** @class */ (function () {
86+
function C(ctorField) {
87+
if (ctorField === void 0) { ctorField = null; }
88+
this.ctorField = ctorField;
89+
this.field = null;
90+
this.roFiled = null;
91+
}
92+
C.prototype.method = function (p) {
93+
if (p === void 0) { p = null; }
94+
};
95+
C.prototype.methodWithRequiredDefault = function (p, req) {
96+
if (p === void 0) { p = null; }
97+
};
98+
C.prototype.methodWithRequiredDefault2 = function (p, req) {
99+
if (p === void 0) { p = null; }
100+
};
101+
return C;
102+
}());
103+
exports.C = C;
104+
exports.default = null;
105+
//// [assertToTypeLiteral.js]
106+
"use strict";
107+
Object.defineProperty(exports, "__esModule", { value: true });
108+
exports.C = exports.fnWithRequiredDefaultParam = exports.fn = exports.vConst = exports.vLet = void 0;
109+
exports.vLet = null;
110+
exports.vConst = null;
111+
function fn(p) {
112+
if (p === void 0) { p = null; }
113+
}
114+
exports.fn = fn;
115+
function fnWithRequiredDefaultParam(p, req) {
116+
if (p === void 0) { p = null; }
117+
}
118+
exports.fnWithRequiredDefaultParam = fnWithRequiredDefaultParam;
119+
var C = /** @class */ (function () {
120+
function C(ctorField) {
121+
if (ctorField === void 0) { ctorField = null; }
122+
this.ctorField = ctorField;
123+
this.field = null;
124+
this.roFiled = null;
125+
}
126+
C.prototype.method = function (p) {
127+
if (p === void 0) { p = null; }
128+
};
129+
C.prototype.methodWithRequiredDefault = function (p, req) {
130+
if (p === void 0) { p = null; }
131+
};
132+
Object.defineProperty(C.prototype, "x", {
133+
get: function () { return null; },
134+
set: function (v) { },
135+
enumerable: false,
136+
configurable: true
137+
});
138+
return C;
139+
}());
140+
exports.C = C;
141+
exports.default = null;
142+
//// [assertToOtherTypes.js]
143+
"use strict";
144+
Object.defineProperty(exports, "__esModule", { value: true });
145+
exports.C = exports.vLiteral = exports.vStringLiteral = exports.vNumberLiteral = void 0;
146+
exports.vNumberLiteral = null;
147+
exports.vStringLiteral = null;
148+
exports.vLiteral = null;
149+
var C = /** @class */ (function () {
150+
function C() {
151+
// Can't know if references contain undefined, fall back to inference
152+
this.tsResolve = null;
153+
this.tsResolve2 = null;
154+
// Simple type. we can add undefined
155+
this.reuseType = null;
156+
this.reuseType2 = null;
157+
this.reuseType3 = null;
158+
this.reuseType4 = null;
159+
this.reuseType5 = null;
160+
this.reuseType6 = null;
161+
this.reuseType7 = null;
162+
this.reuseType8 = null;
163+
this.reuseType9 = null;
164+
}
165+
return C;
166+
}());
167+
exports.C = C;
168+
169+
170+
//// [assertToTypeReferences.d.ts]
171+
export declare let vLet: {
172+
name: string;
173+
};
174+
export declare const vConst: {
175+
name: string;
176+
};
177+
export declare function fn(p?: {
178+
name: string;
179+
}): void;
180+
export declare function fnWithRequiredDefaultParam(p: {
181+
name: string;
182+
}, req: number): void;
183+
export declare class C {
184+
ctorField: {
185+
name: string;
186+
};
187+
field: {
188+
name: string;
189+
};
190+
readonly roFiled: {
191+
name: string;
192+
};
193+
method(p?: {
194+
name: string;
195+
}): void;
196+
methodWithRequiredDefault(p: {
197+
name: string;
198+
}, req: number): void;
199+
methodWithRequiredDefault2(p: {
200+
name: string;
201+
}, req: number): void;
202+
constructor(ctorField?: {
203+
name: string;
204+
});
205+
}
206+
declare const _default: {
207+
name: string;
208+
};
209+
export default _default;
210+
//// [assertToTypeLiteral.d.ts]
211+
export declare let vLet: {
212+
name: string;
213+
};
214+
export declare const vConst: {
215+
name: string;
216+
};
217+
export declare function fn(p?: {
218+
name: string;
219+
}): void;
220+
export declare function fnWithRequiredDefaultParam(p: {
221+
name: string;
222+
}, req: number): void;
223+
export declare class C {
224+
ctorField: {
225+
name: string;
226+
};
227+
field: {
228+
name: string;
229+
};
230+
readonly roFiled: {
231+
name: string;
232+
};
233+
method(p?: {
234+
name: string;
235+
}): void;
236+
methodWithRequiredDefault(p: {
237+
name: string;
238+
}, req: number): void;
239+
constructor(ctorField?: {
240+
name: string;
241+
});
242+
get x(): {
243+
name: string;
244+
};
245+
set x(v: {
246+
name: string;
247+
});
248+
}
249+
declare const _default: {
250+
name: string;
251+
};
252+
export default _default;
253+
//// [assertToOtherTypes.d.ts]
254+
export declare const vNumberLiteral: 1;
255+
export declare const vStringLiteral: "1";
256+
export declare const vLiteral: "1";
257+
type R = {
258+
foo: string;
259+
};
260+
export declare class C {
261+
tsResolve?: R;
262+
tsResolve2?: string | R;
263+
reuseType?: string | ((p: R) => void);
264+
reuseType2?: string | (new (p: R) => R);
265+
reuseType3?: any;
266+
reuseType4?: [R, R, R];
267+
reuseType5?: R[];
268+
reuseType6?: 1 | "2" | 1n;
269+
reuseType7?: "A";
270+
reuseType8?: `${string}-ok`;
271+
reuseType9?: this;
272+
}
273+
export {};

0 commit comments

Comments
 (0)