Skip to content

Commit 8e466ba

Browse files
committed
Add more tests
1 parent 483e8df commit 8e466ba

File tree

5 files changed

+374
-1
lines changed

5 files changed

+374
-1
lines changed

tests/baselines/reference/instantiationExpressions.errors.txt

+48-1
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,13 @@ tests/cases/conformance/types/typeParameters/typeArgumentLists/instantiationExpr
1212
tests/cases/conformance/types/typeParameters/typeArgumentLists/instantiationExpressions.ts(114,16): error TS2635: Type '{ x: string; } | { y: string; }' has no signatures for which the type argument list is applicable.
1313
tests/cases/conformance/types/typeParameters/typeArgumentLists/instantiationExpressions.ts(126,16): error TS2635: Type '(a: string, b: number) => string[]' has no signatures for which the type argument list is applicable.
1414
tests/cases/conformance/types/typeParameters/typeArgumentLists/instantiationExpressions.ts(130,16): error TS2635: Type 'new (a: string, b: number) => string[]' has no signatures for which the type argument list is applicable.
15+
tests/cases/conformance/types/typeParameters/typeArgumentLists/instantiationExpressions.ts(159,40): error TS2344: Type 'U' does not satisfy the constraint 'number'.
16+
Type 'string' is not assignable to type 'number'.
17+
tests/cases/conformance/types/typeParameters/typeArgumentLists/instantiationExpressions.ts(160,40): error TS2344: Type 'U' does not satisfy the constraint 'string'.
18+
Type 'number' is not assignable to type 'string'.
1519

1620

17-
==== tests/cases/conformance/types/typeParameters/typeArgumentLists/instantiationExpressions.ts (14 errors) ====
21+
==== tests/cases/conformance/types/typeParameters/typeArgumentLists/instantiationExpressions.ts (16 errors) ====
1822
declare function fx<T>(x: T): T;
1923
declare function fx<T>(x: T, n: number): T;
2024
declare function fx<T, U>(t: [T, U]): [T, U];
@@ -174,4 +178,47 @@ tests/cases/conformance/types/typeParameters/typeArgumentLists/instantiationExpr
174178
~~~~~~
175179
!!! error TS2635: Type 'new (a: string, b: number) => string[]' has no signatures for which the type argument list is applicable.
176180
}
181+
182+
function makeBox<T>(value: T) {
183+
return { value };
184+
}
185+
186+
type BoxFunc<T> = typeof makeBox<T>; // (value: T) => { value: T }
187+
type StringBoxFunc = BoxFunc<string>; // (value: string) => { value: string }
188+
189+
type Box<T> = ReturnType<typeof makeBox<T>>; // { value: T }
190+
type StringBox = Box<string>; // { value: string }
191+
192+
type A<U> = InstanceType<typeof Array<U>>; // U[]
193+
194+
declare const g1: {
195+
<T>(a: T): { a: T };
196+
new <U>(b: U): { b: U };
197+
}
198+
199+
type T30<V> = typeof g1<V>; // { (a: V) => { a: V }; new (b: V) => { b: V }; }
200+
type T31<A> = ReturnType<T30<A>>; // { a: A }
201+
type T32<B> = InstanceType<T30<B>>; // { b: B }
202+
203+
declare const g2: {
204+
<T extends string>(a: T): T;
205+
new <T extends number>(b: T): T;
206+
}
207+
208+
type T40<U extends string> = typeof g2<U>; // Error
209+
~
210+
!!! error TS2344: Type 'U' does not satisfy the constraint 'number'.
211+
!!! error TS2344: Type 'string' is not assignable to type 'number'.
212+
type T41<U extends number> = typeof g2<U>; // Error
213+
~
214+
!!! error TS2344: Type 'U' does not satisfy the constraint 'string'.
215+
!!! error TS2344: Type 'number' is not assignable to type 'string'.
216+
217+
declare const g3: {
218+
<T extends string>(a: T): T;
219+
new <T extends number, Q>(b: T): T;
220+
}
221+
222+
type T50<U extends string> = typeof g3<U>; // (a: U) => U
223+
type T51<U extends number> = typeof g3<U, any>; // (b: U) => U
177224

tests/baselines/reference/instantiationExpressions.js

+71
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,43 @@ function f36(f: (new <T>(a: T) => T) | ((a: string, b: number) => string[])) {
130130
function f37(f: (<T>(a: T) => T) | (new (a: string, b: number) => string[])) {
131131
let fs = f<string>; // Error, 'new (a: string, b: number) => string[]' has no applicable signatures
132132
}
133+
134+
function makeBox<T>(value: T) {
135+
return { value };
136+
}
137+
138+
type BoxFunc<T> = typeof makeBox<T>; // (value: T) => { value: T }
139+
type StringBoxFunc = BoxFunc<string>; // (value: string) => { value: string }
140+
141+
type Box<T> = ReturnType<typeof makeBox<T>>; // { value: T }
142+
type StringBox = Box<string>; // { value: string }
143+
144+
type A<U> = InstanceType<typeof Array<U>>; // U[]
145+
146+
declare const g1: {
147+
<T>(a: T): { a: T };
148+
new <U>(b: U): { b: U };
149+
}
150+
151+
type T30<V> = typeof g1<V>; // { (a: V) => { a: V }; new (b: V) => { b: V }; }
152+
type T31<A> = ReturnType<T30<A>>; // { a: A }
153+
type T32<B> = InstanceType<T30<B>>; // { b: B }
154+
155+
declare const g2: {
156+
<T extends string>(a: T): T;
157+
new <T extends number>(b: T): T;
158+
}
159+
160+
type T40<U extends string> = typeof g2<U>; // Error
161+
type T41<U extends number> = typeof g2<U>; // Error
162+
163+
declare const g3: {
164+
<T extends string>(a: T): T;
165+
new <T extends number, Q>(b: T): T;
166+
}
167+
168+
type T50<U extends string> = typeof g3<U>; // (a: U) => U
169+
type T51<U extends number> = typeof g3<U, any>; // (b: U) => U
133170

134171

135172
//// [instantiationExpressions.js]
@@ -221,6 +258,9 @@ function f36(f) {
221258
function f37(f) {
222259
var fs = (f); // Error, 'new (a: string, b: number) => string[]' has no applicable signatures
223260
}
261+
function makeBox(value) {
262+
return { value: value };
263+
}
224264

225265

226266
//// [instantiationExpressions.d.ts]
@@ -301,3 +341,34 @@ declare function f34(f: (new <T>(a: T) => T) | (new <U>(a: U, b: number) => U[])
301341
declare function f35(f: (new <T>(a: T) => T) | (<U>(a: U, b: number) => U[])): void;
302342
declare function f36(f: (new <T>(a: T) => T) | ((a: string, b: number) => string[])): void;
303343
declare function f37(f: (<T>(a: T) => T) | (new (a: string, b: number) => string[])): void;
344+
declare function makeBox<T>(value: T): {
345+
value: T;
346+
};
347+
declare type BoxFunc<T> = typeof makeBox<T>;
348+
declare type StringBoxFunc = BoxFunc<string>;
349+
declare type Box<T> = ReturnType<typeof makeBox<T>>;
350+
declare type StringBox = Box<string>;
351+
declare type A<U> = InstanceType<typeof Array<U>>;
352+
declare const g1: {
353+
<T>(a: T): {
354+
a: T;
355+
};
356+
new <U>(b: U): {
357+
b: U;
358+
};
359+
};
360+
declare type T30<V> = typeof g1<V>;
361+
declare type T31<A> = ReturnType<T30<A>>;
362+
declare type T32<B> = InstanceType<T30<B>>;
363+
declare const g2: {
364+
<T extends string>(a: T): T;
365+
new <T extends number>(b: T): T;
366+
};
367+
declare type T40<U extends string> = typeof g2<U>;
368+
declare type T41<U extends number> = typeof g2<U>;
369+
declare const g3: {
370+
<T extends string>(a: T): T;
371+
new <T extends number, Q>(b: T): T;
372+
};
373+
declare type T50<U extends string> = typeof g3<U>;
374+
declare type T51<U extends number> = typeof g3<U, any>;

tests/baselines/reference/instantiationExpressions.symbols

+133
Original file line numberDiff line numberDiff line change
@@ -490,3 +490,136 @@ function f37(f: (<T>(a: T) => T) | (new (a: string, b: number) => string[])) {
490490
>f : Symbol(f, Decl(instantiationExpressions.ts, 128, 13))
491491
}
492492

493+
function makeBox<T>(value: T) {
494+
>makeBox : Symbol(makeBox, Decl(instantiationExpressions.ts, 130, 1))
495+
>T : Symbol(T, Decl(instantiationExpressions.ts, 132, 17))
496+
>value : Symbol(value, Decl(instantiationExpressions.ts, 132, 20))
497+
>T : Symbol(T, Decl(instantiationExpressions.ts, 132, 17))
498+
499+
return { value };
500+
>value : Symbol(value, Decl(instantiationExpressions.ts, 133, 12))
501+
}
502+
503+
type BoxFunc<T> = typeof makeBox<T>; // (value: T) => { value: T }
504+
>BoxFunc : Symbol(BoxFunc, Decl(instantiationExpressions.ts, 134, 1))
505+
>T : Symbol(T, Decl(instantiationExpressions.ts, 136, 13))
506+
>makeBox : Symbol(makeBox, Decl(instantiationExpressions.ts, 130, 1))
507+
>T : Symbol(T, Decl(instantiationExpressions.ts, 136, 13))
508+
509+
type StringBoxFunc = BoxFunc<string>; // (value: string) => { value: string }
510+
>StringBoxFunc : Symbol(StringBoxFunc, Decl(instantiationExpressions.ts, 136, 36))
511+
>BoxFunc : Symbol(BoxFunc, Decl(instantiationExpressions.ts, 134, 1))
512+
513+
type Box<T> = ReturnType<typeof makeBox<T>>; // { value: T }
514+
>Box : Symbol(Box, Decl(instantiationExpressions.ts, 137, 37))
515+
>T : Symbol(T, Decl(instantiationExpressions.ts, 139, 9))
516+
>ReturnType : Symbol(ReturnType, Decl(lib.es5.d.ts, --, --))
517+
>makeBox : Symbol(makeBox, Decl(instantiationExpressions.ts, 130, 1))
518+
>T : Symbol(T, Decl(instantiationExpressions.ts, 139, 9))
519+
520+
type StringBox = Box<string>; // { value: string }
521+
>StringBox : Symbol(StringBox, Decl(instantiationExpressions.ts, 139, 44))
522+
>Box : Symbol(Box, Decl(instantiationExpressions.ts, 137, 37))
523+
524+
type A<U> = InstanceType<typeof Array<U>>; // U[]
525+
>A : Symbol(A, Decl(instantiationExpressions.ts, 140, 29))
526+
>U : Symbol(U, Decl(instantiationExpressions.ts, 142, 7))
527+
>InstanceType : Symbol(InstanceType, Decl(lib.es5.d.ts, --, --))
528+
>Array : Symbol(Array, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --))
529+
>U : Symbol(U, Decl(instantiationExpressions.ts, 142, 7))
530+
531+
declare const g1: {
532+
>g1 : Symbol(g1, Decl(instantiationExpressions.ts, 144, 13))
533+
534+
<T>(a: T): { a: T };
535+
>T : Symbol(T, Decl(instantiationExpressions.ts, 145, 5))
536+
>a : Symbol(a, Decl(instantiationExpressions.ts, 145, 8))
537+
>T : Symbol(T, Decl(instantiationExpressions.ts, 145, 5))
538+
>a : Symbol(a, Decl(instantiationExpressions.ts, 145, 16))
539+
>T : Symbol(T, Decl(instantiationExpressions.ts, 145, 5))
540+
541+
new <U>(b: U): { b: U };
542+
>U : Symbol(U, Decl(instantiationExpressions.ts, 146, 9))
543+
>b : Symbol(b, Decl(instantiationExpressions.ts, 146, 12))
544+
>U : Symbol(U, Decl(instantiationExpressions.ts, 146, 9))
545+
>b : Symbol(b, Decl(instantiationExpressions.ts, 146, 20))
546+
>U : Symbol(U, Decl(instantiationExpressions.ts, 146, 9))
547+
}
548+
549+
type T30<V> = typeof g1<V>; // { (a: V) => { a: V }; new (b: V) => { b: V }; }
550+
>T30 : Symbol(T30, Decl(instantiationExpressions.ts, 147, 1))
551+
>V : Symbol(V, Decl(instantiationExpressions.ts, 149, 9))
552+
>g1 : Symbol(g1, Decl(instantiationExpressions.ts, 144, 13))
553+
>V : Symbol(V, Decl(instantiationExpressions.ts, 149, 9))
554+
555+
type T31<A> = ReturnType<T30<A>>; // { a: A }
556+
>T31 : Symbol(T31, Decl(instantiationExpressions.ts, 149, 27))
557+
>A : Symbol(A, Decl(instantiationExpressions.ts, 150, 9))
558+
>ReturnType : Symbol(ReturnType, Decl(lib.es5.d.ts, --, --))
559+
>T30 : Symbol(T30, Decl(instantiationExpressions.ts, 147, 1))
560+
>A : Symbol(A, Decl(instantiationExpressions.ts, 150, 9))
561+
562+
type T32<B> = InstanceType<T30<B>>; // { b: B }
563+
>T32 : Symbol(T32, Decl(instantiationExpressions.ts, 150, 33))
564+
>B : Symbol(B, Decl(instantiationExpressions.ts, 151, 9))
565+
>InstanceType : Symbol(InstanceType, Decl(lib.es5.d.ts, --, --))
566+
>T30 : Symbol(T30, Decl(instantiationExpressions.ts, 147, 1))
567+
>B : Symbol(B, Decl(instantiationExpressions.ts, 151, 9))
568+
569+
declare const g2: {
570+
>g2 : Symbol(g2, Decl(instantiationExpressions.ts, 153, 13))
571+
572+
<T extends string>(a: T): T;
573+
>T : Symbol(T, Decl(instantiationExpressions.ts, 154, 5))
574+
>a : Symbol(a, Decl(instantiationExpressions.ts, 154, 23))
575+
>T : Symbol(T, Decl(instantiationExpressions.ts, 154, 5))
576+
>T : Symbol(T, Decl(instantiationExpressions.ts, 154, 5))
577+
578+
new <T extends number>(b: T): T;
579+
>T : Symbol(T, Decl(instantiationExpressions.ts, 155, 9))
580+
>b : Symbol(b, Decl(instantiationExpressions.ts, 155, 27))
581+
>T : Symbol(T, Decl(instantiationExpressions.ts, 155, 9))
582+
>T : Symbol(T, Decl(instantiationExpressions.ts, 155, 9))
583+
}
584+
585+
type T40<U extends string> = typeof g2<U>; // Error
586+
>T40 : Symbol(T40, Decl(instantiationExpressions.ts, 156, 1))
587+
>U : Symbol(U, Decl(instantiationExpressions.ts, 158, 9))
588+
>g2 : Symbol(g2, Decl(instantiationExpressions.ts, 153, 13))
589+
>U : Symbol(U, Decl(instantiationExpressions.ts, 158, 9))
590+
591+
type T41<U extends number> = typeof g2<U>; // Error
592+
>T41 : Symbol(T41, Decl(instantiationExpressions.ts, 158, 42))
593+
>U : Symbol(U, Decl(instantiationExpressions.ts, 159, 9))
594+
>g2 : Symbol(g2, Decl(instantiationExpressions.ts, 153, 13))
595+
>U : Symbol(U, Decl(instantiationExpressions.ts, 159, 9))
596+
597+
declare const g3: {
598+
>g3 : Symbol(g3, Decl(instantiationExpressions.ts, 161, 13))
599+
600+
<T extends string>(a: T): T;
601+
>T : Symbol(T, Decl(instantiationExpressions.ts, 162, 5))
602+
>a : Symbol(a, Decl(instantiationExpressions.ts, 162, 23))
603+
>T : Symbol(T, Decl(instantiationExpressions.ts, 162, 5))
604+
>T : Symbol(T, Decl(instantiationExpressions.ts, 162, 5))
605+
606+
new <T extends number, Q>(b: T): T;
607+
>T : Symbol(T, Decl(instantiationExpressions.ts, 163, 9))
608+
>Q : Symbol(Q, Decl(instantiationExpressions.ts, 163, 26))
609+
>b : Symbol(b, Decl(instantiationExpressions.ts, 163, 30))
610+
>T : Symbol(T, Decl(instantiationExpressions.ts, 163, 9))
611+
>T : Symbol(T, Decl(instantiationExpressions.ts, 163, 9))
612+
}
613+
614+
type T50<U extends string> = typeof g3<U>; // (a: U) => U
615+
>T50 : Symbol(T50, Decl(instantiationExpressions.ts, 164, 1))
616+
>U : Symbol(U, Decl(instantiationExpressions.ts, 166, 9))
617+
>g3 : Symbol(g3, Decl(instantiationExpressions.ts, 161, 13))
618+
>U : Symbol(U, Decl(instantiationExpressions.ts, 166, 9))
619+
620+
type T51<U extends number> = typeof g3<U, any>; // (b: U) => U
621+
>T51 : Symbol(T51, Decl(instantiationExpressions.ts, 166, 42))
622+
>U : Symbol(U, Decl(instantiationExpressions.ts, 167, 9))
623+
>g3 : Symbol(g3, Decl(instantiationExpressions.ts, 161, 13))
624+
>U : Symbol(U, Decl(instantiationExpressions.ts, 167, 9))
625+

tests/baselines/reference/instantiationExpressions.types

+85
Original file line numberDiff line numberDiff line change
@@ -383,3 +383,88 @@ function f37(f: (<T>(a: T) => T) | (new (a: string, b: number) => string[])) {
383383
>f : (<T>(a: T) => T) | (new (a: string, b: number) => string[])
384384
}
385385

386+
function makeBox<T>(value: T) {
387+
>makeBox : <T>(value: T) => { value: T; }
388+
>value : T
389+
390+
return { value };
391+
>{ value } : { value: T; }
392+
>value : T
393+
}
394+
395+
type BoxFunc<T> = typeof makeBox<T>; // (value: T) => { value: T }
396+
>BoxFunc : (value: T) => { value: T; }
397+
>makeBox : <T>(value: T) => { value: T; }
398+
399+
type StringBoxFunc = BoxFunc<string>; // (value: string) => { value: string }
400+
>StringBoxFunc : StringBoxFunc
401+
402+
type Box<T> = ReturnType<typeof makeBox<T>>; // { value: T }
403+
>Box : { value: T; }
404+
>makeBox : <T>(value: T) => { value: T; }
405+
406+
type StringBox = Box<string>; // { value: string }
407+
>StringBox : StringBox
408+
409+
type A<U> = InstanceType<typeof Array<U>>; // U[]
410+
>A : U[]
411+
>Array : ArrayConstructor
412+
413+
declare const g1: {
414+
>g1 : { <T>(a: T): { a: T; }; new <U>(b: U): { b: U; }; }
415+
416+
<T>(a: T): { a: T };
417+
>a : T
418+
>a : T
419+
420+
new <U>(b: U): { b: U };
421+
>b : U
422+
>b : U
423+
}
424+
425+
type T30<V> = typeof g1<V>; // { (a: V) => { a: V }; new (b: V) => { b: V }; }
426+
>T30 : { (a: V): { a: V; }; new (b: V): { b: V; }; }
427+
>g1 : { <T>(a: T): { a: T; }; new <U>(b: U): { b: U; }; }
428+
429+
type T31<A> = ReturnType<T30<A>>; // { a: A }
430+
>T31 : { a: A; }
431+
432+
type T32<B> = InstanceType<T30<B>>; // { b: B }
433+
>T32 : { b: B; }
434+
435+
declare const g2: {
436+
>g2 : { <T extends string>(a: T): T; new <T extends number>(b: T): T; }
437+
438+
<T extends string>(a: T): T;
439+
>a : T
440+
441+
new <T extends number>(b: T): T;
442+
>b : T
443+
}
444+
445+
type T40<U extends string> = typeof g2<U>; // Error
446+
>T40 : { (a: U): U; new <T extends number>(b: T): T; }
447+
>g2 : { <T extends string>(a: T): T; new <T extends number>(b: T): T; }
448+
449+
type T41<U extends number> = typeof g2<U>; // Error
450+
>T41 : { <T extends string>(a: T): T; new (b: U): U; }
451+
>g2 : { <T extends string>(a: T): T; new <T extends number>(b: T): T; }
452+
453+
declare const g3: {
454+
>g3 : { <T extends string>(a: T): T; new <T extends number, Q>(b: T): T; }
455+
456+
<T extends string>(a: T): T;
457+
>a : T
458+
459+
new <T extends number, Q>(b: T): T;
460+
>b : T
461+
}
462+
463+
type T50<U extends string> = typeof g3<U>; // (a: U) => U
464+
>T50 : (a: U) => U
465+
>g3 : { <T extends string>(a: T): T; new <T extends number, Q>(b: T): T; }
466+
467+
type T51<U extends number> = typeof g3<U, any>; // (b: U) => U
468+
>T51 : new (b: U) => U
469+
>g3 : { <T extends string>(a: T): T; new <T extends number, Q>(b: T): T; }
470+

0 commit comments

Comments
 (0)