Skip to content

Commit 132638b

Browse files
committed
Add test
1 parent 088fdf6 commit 132638b

File tree

4 files changed

+1426
-0
lines changed

4 files changed

+1426
-0
lines changed
Lines changed: 292 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,292 @@
1+
//// [declarationEmitGlobalThisPreserved.ts]
2+
// Adding this makes tooltips fail too.
3+
// declare global {
4+
// namespace isNaN {
5+
// const prop: number;
6+
// }
7+
// }
8+
9+
// Broken inference cases.
10+
11+
export const a1 = (isNaN: typeof globalThis.isNaN): typeof globalThis.isNaN => isNaN;
12+
export const a2 = (isNaN: typeof globalThis.isNaN, bar?: typeof globalThis.isNaN): typeof globalThis.isNaN => bar ?? isNaN;
13+
export const a3 = (isNaN: number, bar: typeof globalThis.isNaN): typeof globalThis.isNaN => bar;
14+
export const a4 = (isNaN: number): typeof globalThis.isNaN => globalThis.isNaN;
15+
16+
export const aObj = {
17+
a1: (isNaN: typeof globalThis.isNaN): typeof globalThis.isNaN => isNaN,
18+
a2: (isNaN: typeof globalThis.isNaN, bar?: typeof globalThis.isNaN): typeof globalThis.isNaN => bar ?? isNaN,
19+
a3: (isNaN: number, bar: typeof globalThis.isNaN): typeof globalThis.isNaN => bar,
20+
a4: (isNaN: number): typeof globalThis.isNaN => globalThis.isNaN,
21+
}
22+
23+
export type a4Return = ReturnType<ReturnType<typeof a4>>;
24+
export type a4oReturn = ReturnType<ReturnType<typeof aObj['a4']>>;
25+
26+
export const b1 = (isNaN: typeof globalThis.isNaN) => isNaN;
27+
export const b2 = (isNaN: typeof globalThis.isNaN, bar?: typeof globalThis.isNaN) => bar ?? isNaN;
28+
export const b3 = (isNaN: number, bar: typeof globalThis.isNaN) => bar;
29+
export const b4 = (isNaN: number) => globalThis.isNaN;
30+
31+
export const bObj = {
32+
b1: (isNaN: typeof globalThis.isNaN) => isNaN,
33+
b2: (isNaN: typeof globalThis.isNaN, bar?: typeof globalThis.isNaN) => bar ?? isNaN,
34+
b3: (isNaN: number, bar: typeof globalThis.isNaN) => bar,
35+
b4: (isNaN: number) => globalThis.isNaN,
36+
}
37+
38+
export type b4Return = ReturnType<ReturnType<typeof b4>>;
39+
export type b4oReturn = ReturnType<ReturnType<typeof bObj['b4']>>;
40+
41+
export function c1(isNaN: typeof globalThis.isNaN) { return isNaN }
42+
export function c2(isNaN: typeof globalThis.isNaN, bar?: typeof globalThis.isNaN) { return bar ?? isNaN }
43+
export function c3(isNaN: number, bar: typeof globalThis.isNaN) { return bar }
44+
export function c4(isNaN: number) { return globalThis.isNaN; }
45+
46+
export const cObj = {
47+
c1(isNaN: typeof globalThis.isNaN) { return isNaN },
48+
c2(isNaN: typeof globalThis.isNaN, bar?: typeof globalThis.isNaN) { return bar ?? isNaN },
49+
c3(isNaN: number, bar: typeof globalThis.isNaN) { return bar },
50+
c4(isNaN: number) { return globalThis.isNaN; },
51+
}
52+
53+
export type c4Return = ReturnType<ReturnType<typeof c4>>;
54+
export type c4oReturn = ReturnType<ReturnType<typeof cObj['c4']>>;
55+
56+
export function d1() {
57+
const fn = (isNaN: typeof globalThis.isNaN): typeof globalThis.isNaN => isNaN;
58+
return function() { return fn };
59+
}
60+
61+
export function d2() {
62+
const fn = (isNaN: typeof globalThis.isNaN, bar?: typeof globalThis.isNaN): typeof globalThis.isNaN => bar ?? isNaN;
63+
return function() { return fn };
64+
}
65+
66+
export function d3() {
67+
const fn = (isNaN: number, bar: typeof globalThis.isNaN): typeof globalThis.isNaN => bar;
68+
return function() { return fn };
69+
}
70+
71+
export function d4() {
72+
const fn = (isNaN: number): typeof globalThis.isNaN => globalThis.isNaN;
73+
return function() { return fn };
74+
}
75+
76+
export type d4Return = ReturnType<ReturnType<ReturnType<ReturnType<typeof d4>>>>;
77+
78+
export class A {
79+
method1(isNaN: typeof globalThis.isNaN) { return isNaN }
80+
method2(isNaN: typeof globalThis.isNaN, bar?: typeof globalThis.isNaN) { return bar ?? isNaN }
81+
method3(isNaN: number, bar: typeof globalThis.isNaN) { return bar }
82+
method4(isNaN: number) { return globalThis.isNaN; }
83+
}
84+
85+
export function fromParameter(isNaN: number, bar: typeof globalThis.isNaN) {
86+
return function() { return { bar } };
87+
}
88+
89+
// Non-inference cases.
90+
91+
export const explicitlyTypedVariable: (isNaN: typeof globalThis.isNaN) => typeof globalThis.isNaN = (isNaN) => isNaN;
92+
93+
export function explicitlyTypedFunction(isNaN: typeof globalThis.isNaN): typeof globalThis.isNaN {
94+
return isNaN;
95+
};
96+
97+
export type AsObjectProperty = {
98+
isNaN: typeof globalThis.isNaN;
99+
}
100+
101+
export class AsClassProperty {
102+
isNaN?: typeof globalThis.isNaN;
103+
}
104+
105+
export type AsFunctionType = (isNaN: typeof globalThis.isNaN) => typeof globalThis.isNaN;
106+
107+
108+
109+
110+
111+
//// [declarationEmitGlobalThisPreserved.d.ts]
112+
export declare const a1: (isNaN: typeof isNaN) => typeof isNaN;
113+
export declare const a2: (isNaN: typeof isNaN, bar?: typeof isNaN) => typeof isNaN;
114+
export declare const a3: (isNaN: number, bar: typeof isNaN) => typeof isNaN;
115+
export declare const a4: (isNaN: number) => typeof isNaN;
116+
export declare const aObj: {
117+
a1: (isNaN: typeof isNaN) => typeof isNaN;
118+
a2: (isNaN: typeof isNaN, bar?: typeof isNaN) => typeof isNaN;
119+
a3: (isNaN: number, bar: typeof isNaN) => typeof isNaN;
120+
a4: (isNaN: number) => typeof isNaN;
121+
};
122+
export type a4Return = ReturnType<ReturnType<typeof a4>>;
123+
export type a4oReturn = ReturnType<ReturnType<typeof aObj['a4']>>;
124+
export declare const b1: (isNaN: typeof isNaN) => typeof isNaN;
125+
export declare const b2: (isNaN: typeof isNaN, bar?: typeof isNaN) => typeof isNaN;
126+
export declare const b3: (isNaN: number, bar: typeof isNaN) => typeof isNaN;
127+
export declare const b4: (isNaN: number) => typeof isNaN;
128+
export declare const bObj: {
129+
b1: (isNaN: typeof isNaN) => typeof isNaN;
130+
b2: (isNaN: typeof isNaN, bar?: typeof isNaN) => typeof isNaN;
131+
b3: (isNaN: number, bar: typeof isNaN) => typeof isNaN;
132+
b4: (isNaN: number) => typeof isNaN;
133+
};
134+
export type b4Return = ReturnType<ReturnType<typeof b4>>;
135+
export type b4oReturn = ReturnType<ReturnType<typeof bObj['b4']>>;
136+
export declare function c1(isNaN: typeof globalThis.isNaN): typeof globalThis.isNaN;
137+
export declare function c2(isNaN: typeof globalThis.isNaN, bar?: typeof globalThis.isNaN): typeof globalThis.isNaN;
138+
export declare function c3(isNaN: number, bar: typeof globalThis.isNaN): typeof globalThis.isNaN;
139+
export declare function c4(isNaN: number): typeof globalThis.isNaN;
140+
export declare const cObj: {
141+
c1(isNaN: typeof isNaN): typeof isNaN;
142+
c2(isNaN: typeof isNaN, bar?: typeof isNaN): typeof isNaN;
143+
c3(isNaN: number, bar: typeof isNaN): typeof isNaN;
144+
c4(isNaN: number): typeof isNaN;
145+
};
146+
export type c4Return = ReturnType<ReturnType<typeof c4>>;
147+
export type c4oReturn = ReturnType<ReturnType<typeof cObj['c4']>>;
148+
export declare function d1(): () => (isNaN: typeof isNaN) => typeof isNaN;
149+
export declare function d2(): () => (isNaN: typeof isNaN, bar?: typeof isNaN) => typeof isNaN;
150+
export declare function d3(): () => (isNaN: number, bar: typeof isNaN) => typeof isNaN;
151+
export declare function d4(): () => (isNaN: number) => typeof isNaN;
152+
export type d4Return = ReturnType<ReturnType<ReturnType<ReturnType<typeof d4>>>>;
153+
export declare class A {
154+
method1(isNaN: typeof globalThis.isNaN): typeof globalThis.isNaN;
155+
method2(isNaN: typeof globalThis.isNaN, bar?: typeof globalThis.isNaN): typeof globalThis.isNaN;
156+
method3(isNaN: number, bar: typeof globalThis.isNaN): typeof globalThis.isNaN;
157+
method4(isNaN: number): typeof globalThis.isNaN;
158+
}
159+
export declare function fromParameter(isNaN: number, bar: typeof globalThis.isNaN): () => {
160+
bar: typeof globalThis.isNaN;
161+
};
162+
export declare const explicitlyTypedVariable: (isNaN: typeof globalThis.isNaN) => typeof globalThis.isNaN;
163+
export declare function explicitlyTypedFunction(isNaN: typeof globalThis.isNaN): typeof globalThis.isNaN;
164+
export type AsObjectProperty = {
165+
isNaN: typeof globalThis.isNaN;
166+
};
167+
export declare class AsClassProperty {
168+
isNaN?: typeof globalThis.isNaN;
169+
}
170+
export type AsFunctionType = (isNaN: typeof globalThis.isNaN) => typeof globalThis.isNaN;
171+
172+
173+
//// [DtsFileErrors]
174+
175+
176+
tests/cases/compiler/declarationEmitGlobalThisPreserved.d.ts(1,27): error TS2502: 'isNaN' is referenced directly or indirectly in its own type annotation.
177+
tests/cases/compiler/declarationEmitGlobalThisPreserved.d.ts(2,27): error TS2502: 'isNaN' is referenced directly or indirectly in its own type annotation.
178+
tests/cases/compiler/declarationEmitGlobalThisPreserved.d.ts(6,10): error TS2502: 'isNaN' is referenced directly or indirectly in its own type annotation.
179+
tests/cases/compiler/declarationEmitGlobalThisPreserved.d.ts(7,10): error TS2502: 'isNaN' is referenced directly or indirectly in its own type annotation.
180+
tests/cases/compiler/declarationEmitGlobalThisPreserved.d.ts(11,35): error TS2344: Type 'number' does not satisfy the constraint '(...args: any) => any'.
181+
tests/cases/compiler/declarationEmitGlobalThisPreserved.d.ts(12,36): error TS2344: Type 'number' does not satisfy the constraint '(...args: any) => any'.
182+
tests/cases/compiler/declarationEmitGlobalThisPreserved.d.ts(13,27): error TS2502: 'isNaN' is referenced directly or indirectly in its own type annotation.
183+
tests/cases/compiler/declarationEmitGlobalThisPreserved.d.ts(14,27): error TS2502: 'isNaN' is referenced directly or indirectly in its own type annotation.
184+
tests/cases/compiler/declarationEmitGlobalThisPreserved.d.ts(18,10): error TS2502: 'isNaN' is referenced directly or indirectly in its own type annotation.
185+
tests/cases/compiler/declarationEmitGlobalThisPreserved.d.ts(19,10): error TS2502: 'isNaN' is referenced directly or indirectly in its own type annotation.
186+
tests/cases/compiler/declarationEmitGlobalThisPreserved.d.ts(23,35): error TS2344: Type 'number' does not satisfy the constraint '(...args: any) => any'.
187+
tests/cases/compiler/declarationEmitGlobalThisPreserved.d.ts(24,36): error TS2344: Type 'number' does not satisfy the constraint '(...args: any) => any'.
188+
tests/cases/compiler/declarationEmitGlobalThisPreserved.d.ts(30,8): error TS2502: 'isNaN' is referenced directly or indirectly in its own type annotation.
189+
tests/cases/compiler/declarationEmitGlobalThisPreserved.d.ts(31,8): error TS2502: 'isNaN' is referenced directly or indirectly in its own type annotation.
190+
tests/cases/compiler/declarationEmitGlobalThisPreserved.d.ts(36,36): error TS2344: Type 'number' does not satisfy the constraint '(...args: any) => any'.
191+
tests/cases/compiler/declarationEmitGlobalThisPreserved.d.ts(37,38): error TS2502: 'isNaN' is referenced directly or indirectly in its own type annotation.
192+
tests/cases/compiler/declarationEmitGlobalThisPreserved.d.ts(38,38): error TS2502: 'isNaN' is referenced directly or indirectly in its own type annotation.
193+
tests/cases/compiler/declarationEmitGlobalThisPreserved.d.ts(41,35): error TS2344: Type 'number' does not satisfy the constraint '(...args: any) => any'.
194+
195+
196+
==== tests/cases/compiler/declarationEmitGlobalThisPreserved.d.ts (18 errors) ====
197+
export declare const a1: (isNaN: typeof isNaN) => typeof isNaN;
198+
~~~~~~~~~~~~~~~~~~~
199+
!!! error TS2502: 'isNaN' is referenced directly or indirectly in its own type annotation.
200+
export declare const a2: (isNaN: typeof isNaN, bar?: typeof isNaN) => typeof isNaN;
201+
~~~~~~~~~~~~~~~~~~~
202+
!!! error TS2502: 'isNaN' is referenced directly or indirectly in its own type annotation.
203+
export declare const a3: (isNaN: number, bar: typeof isNaN) => typeof isNaN;
204+
export declare const a4: (isNaN: number) => typeof isNaN;
205+
export declare const aObj: {
206+
a1: (isNaN: typeof isNaN) => typeof isNaN;
207+
~~~~~~~~~~~~~~~~~~~
208+
!!! error TS2502: 'isNaN' is referenced directly or indirectly in its own type annotation.
209+
a2: (isNaN: typeof isNaN, bar?: typeof isNaN) => typeof isNaN;
210+
~~~~~~~~~~~~~~~~~~~
211+
!!! error TS2502: 'isNaN' is referenced directly or indirectly in its own type annotation.
212+
a3: (isNaN: number, bar: typeof isNaN) => typeof isNaN;
213+
a4: (isNaN: number) => typeof isNaN;
214+
};
215+
export type a4Return = ReturnType<ReturnType<typeof a4>>;
216+
~~~~~~~~~~~~~~~~~~~~~
217+
!!! error TS2344: Type 'number' does not satisfy the constraint '(...args: any) => any'.
218+
export type a4oReturn = ReturnType<ReturnType<typeof aObj['a4']>>;
219+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
220+
!!! error TS2344: Type 'number' does not satisfy the constraint '(...args: any) => any'.
221+
export declare const b1: (isNaN: typeof isNaN) => typeof isNaN;
222+
~~~~~~~~~~~~~~~~~~~
223+
!!! error TS2502: 'isNaN' is referenced directly or indirectly in its own type annotation.
224+
export declare const b2: (isNaN: typeof isNaN, bar?: typeof isNaN) => typeof isNaN;
225+
~~~~~~~~~~~~~~~~~~~
226+
!!! error TS2502: 'isNaN' is referenced directly or indirectly in its own type annotation.
227+
export declare const b3: (isNaN: number, bar: typeof isNaN) => typeof isNaN;
228+
export declare const b4: (isNaN: number) => typeof isNaN;
229+
export declare const bObj: {
230+
b1: (isNaN: typeof isNaN) => typeof isNaN;
231+
~~~~~~~~~~~~~~~~~~~
232+
!!! error TS2502: 'isNaN' is referenced directly or indirectly in its own type annotation.
233+
b2: (isNaN: typeof isNaN, bar?: typeof isNaN) => typeof isNaN;
234+
~~~~~~~~~~~~~~~~~~~
235+
!!! error TS2502: 'isNaN' is referenced directly or indirectly in its own type annotation.
236+
b3: (isNaN: number, bar: typeof isNaN) => typeof isNaN;
237+
b4: (isNaN: number) => typeof isNaN;
238+
};
239+
export type b4Return = ReturnType<ReturnType<typeof b4>>;
240+
~~~~~~~~~~~~~~~~~~~~~
241+
!!! error TS2344: Type 'number' does not satisfy the constraint '(...args: any) => any'.
242+
export type b4oReturn = ReturnType<ReturnType<typeof bObj['b4']>>;
243+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
244+
!!! error TS2344: Type 'number' does not satisfy the constraint '(...args: any) => any'.
245+
export declare function c1(isNaN: typeof globalThis.isNaN): typeof globalThis.isNaN;
246+
export declare function c2(isNaN: typeof globalThis.isNaN, bar?: typeof globalThis.isNaN): typeof globalThis.isNaN;
247+
export declare function c3(isNaN: number, bar: typeof globalThis.isNaN): typeof globalThis.isNaN;
248+
export declare function c4(isNaN: number): typeof globalThis.isNaN;
249+
export declare const cObj: {
250+
c1(isNaN: typeof isNaN): typeof isNaN;
251+
~~~~~~~~~~~~~~~~~~~
252+
!!! error TS2502: 'isNaN' is referenced directly or indirectly in its own type annotation.
253+
c2(isNaN: typeof isNaN, bar?: typeof isNaN): typeof isNaN;
254+
~~~~~~~~~~~~~~~~~~~
255+
!!! error TS2502: 'isNaN' is referenced directly or indirectly in its own type annotation.
256+
c3(isNaN: number, bar: typeof isNaN): typeof isNaN;
257+
c4(isNaN: number): typeof isNaN;
258+
};
259+
export type c4Return = ReturnType<ReturnType<typeof c4>>;
260+
export type c4oReturn = ReturnType<ReturnType<typeof cObj['c4']>>;
261+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
262+
!!! error TS2344: Type 'number' does not satisfy the constraint '(...args: any) => any'.
263+
export declare function d1(): () => (isNaN: typeof isNaN) => typeof isNaN;
264+
~~~~~~~~~~~~~~~~~~~
265+
!!! error TS2502: 'isNaN' is referenced directly or indirectly in its own type annotation.
266+
export declare function d2(): () => (isNaN: typeof isNaN, bar?: typeof isNaN) => typeof isNaN;
267+
~~~~~~~~~~~~~~~~~~~
268+
!!! error TS2502: 'isNaN' is referenced directly or indirectly in its own type annotation.
269+
export declare function d3(): () => (isNaN: number, bar: typeof isNaN) => typeof isNaN;
270+
export declare function d4(): () => (isNaN: number) => typeof isNaN;
271+
export type d4Return = ReturnType<ReturnType<ReturnType<ReturnType<typeof d4>>>>;
272+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
273+
!!! error TS2344: Type 'number' does not satisfy the constraint '(...args: any) => any'.
274+
export declare class A {
275+
method1(isNaN: typeof globalThis.isNaN): typeof globalThis.isNaN;
276+
method2(isNaN: typeof globalThis.isNaN, bar?: typeof globalThis.isNaN): typeof globalThis.isNaN;
277+
method3(isNaN: number, bar: typeof globalThis.isNaN): typeof globalThis.isNaN;
278+
method4(isNaN: number): typeof globalThis.isNaN;
279+
}
280+
export declare function fromParameter(isNaN: number, bar: typeof globalThis.isNaN): () => {
281+
bar: typeof globalThis.isNaN;
282+
};
283+
export declare const explicitlyTypedVariable: (isNaN: typeof globalThis.isNaN) => typeof globalThis.isNaN;
284+
export declare function explicitlyTypedFunction(isNaN: typeof globalThis.isNaN): typeof globalThis.isNaN;
285+
export type AsObjectProperty = {
286+
isNaN: typeof globalThis.isNaN;
287+
};
288+
export declare class AsClassProperty {
289+
isNaN?: typeof globalThis.isNaN;
290+
}
291+
export type AsFunctionType = (isNaN: typeof globalThis.isNaN) => typeof globalThis.isNaN;
292+

0 commit comments

Comments
 (0)