Skip to content

Commit ed4e812

Browse files
committed
Add tests
1 parent f5639d7 commit ed4e812

File tree

5 files changed

+529
-382
lines changed

5 files changed

+529
-382
lines changed

tests/baselines/reference/variadicTuples1.errors.txt

+33-3
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,20 @@ tests/cases/conformance/types/tuple/variadicTuples1.ts(191,5): error TS2322: Typ
3535
'T' is assignable to the constraint of type 'U', but 'U' could be instantiated with a different subtype of constraint 'readonly string[]'.
3636
tests/cases/conformance/types/tuple/variadicTuples1.ts(203,5): error TS2322: Type 'string' is not assignable to type 'keyof [1, 2, ...T]'.
3737
Type '"2"' is not assignable to type '"0" | "1" | keyof T[]'.
38-
tests/cases/conformance/types/tuple/variadicTuples1.ts(357,26): error TS2322: Type 'string' is not assignable to type 'number'.
39-
tests/cases/conformance/types/tuple/variadicTuples1.ts(397,7): error TS2322: Type '[boolean, false]' is not assignable to type '[...number[], boolean]'.
38+
tests/cases/conformance/types/tuple/variadicTuples1.ts(213,5): error TS2322: Type '[...T, ...T]' is not assignable to type '[unknown, unknown]'.
39+
Type '[] | [unknown] | [unknown, unknown]' is not assignable to type '[unknown, unknown]'.
40+
Type '[]' is not assignable to type '[unknown, unknown]'.
41+
Source has 0 element(s) but target requires 2.
42+
tests/cases/conformance/types/tuple/variadicTuples1.ts(217,5): error TS2322: Type '[...T, ...T]' is not assignable to type '[unknown, unknown]'.
43+
Type 'unknown[]' is not assignable to type '[unknown, unknown]'.
44+
Target requires 2 element(s) but source may have fewer.
45+
tests/cases/conformance/types/tuple/variadicTuples1.ts(371,26): error TS2322: Type 'string' is not assignable to type 'number'.
46+
tests/cases/conformance/types/tuple/variadicTuples1.ts(411,7): error TS2322: Type '[boolean, false]' is not assignable to type '[...number[], boolean]'.
4047
Type at position 0 in source is not compatible with type at position 0 in target.
4148
Type 'boolean' is not assignable to type 'number'.
4249

4350

44-
==== tests/cases/conformance/types/tuple/variadicTuples1.ts (20 errors) ====
51+
==== tests/cases/conformance/types/tuple/variadicTuples1.ts (22 errors) ====
4552
// Variadics in tuple types
4653

4754
type TV0<T extends unknown[]> = [string, ...T];
@@ -303,6 +310,29 @@ tests/cases/conformance/types/tuple/variadicTuples1.ts(397,7): error TS2322: Typ
303310
!!! error TS2322: Type '"2"' is not assignable to type '"0" | "1" | keyof T[]'.
304311
}
305312

313+
// Constraints of variadic tuple types
314+
315+
function ft16<T extends [unknown]>(x: [unknown, unknown], y: [...T, ...T]) {
316+
x = y;
317+
}
318+
319+
function ft17<T extends [] | [unknown]>(x: [unknown, unknown], y: [...T, ...T]) {
320+
x = y;
321+
~
322+
!!! error TS2322: Type '[...T, ...T]' is not assignable to type '[unknown, unknown]'.
323+
!!! error TS2322: Type '[] | [unknown] | [unknown, unknown]' is not assignable to type '[unknown, unknown]'.
324+
!!! error TS2322: Type '[]' is not assignable to type '[unknown, unknown]'.
325+
!!! error TS2322: Source has 0 element(s) but target requires 2.
326+
}
327+
328+
function ft18<T extends unknown[]>(x: [unknown, unknown], y: [...T, ...T]) {
329+
x = y;
330+
~
331+
!!! error TS2322: Type '[...T, ...T]' is not assignable to type '[unknown, unknown]'.
332+
!!! error TS2322: Type 'unknown[]' is not assignable to type '[unknown, unknown]'.
333+
!!! error TS2322: Target requires 2 element(s) but source may have fewer.
334+
}
335+
306336
// Inference between variadic tuple types
307337

308338
type First<T extends readonly unknown[]> =

tests/baselines/reference/variadicTuples1.js

+27
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,20 @@ function f15<T extends string[], U extends T>(k0: keyof T, k1: keyof [...T], k2:
204204
k3 = '2'; // Error
205205
}
206206

207+
// Constraints of variadic tuple types
208+
209+
function ft16<T extends [unknown]>(x: [unknown, unknown], y: [...T, ...T]) {
210+
x = y;
211+
}
212+
213+
function ft17<T extends [] | [unknown]>(x: [unknown, unknown], y: [...T, ...T]) {
214+
x = y;
215+
}
216+
217+
function ft18<T extends unknown[]>(x: [unknown, unknown], y: [...T, ...T]) {
218+
x = y;
219+
}
220+
207221
// Inference between variadic tuple types
208222

209223
type First<T extends readonly unknown[]> =
@@ -546,6 +560,16 @@ function f15(k0, k1, k2, k3) {
546560
k3 = '1';
547561
k3 = '2'; // Error
548562
}
563+
// Constraints of variadic tuple types
564+
function ft16(x, y) {
565+
x = y;
566+
}
567+
function ft17(x, y) {
568+
x = y;
569+
}
570+
function ft18(x, y) {
571+
x = y;
572+
}
549573
// Inference to [...T, ...U] with implied arity for T
550574
function curry(f) {
551575
var a = [];
@@ -682,6 +706,9 @@ declare function f12<T extends readonly unknown[]>(t: T, m: [...T], r: readonly
682706
declare function f13<T extends string[], U extends T>(t0: T, t1: [...T], t2: [...U]): void;
683707
declare function f14<T extends readonly string[], U extends T>(t0: T, t1: [...T], t2: [...U]): void;
684708
declare function f15<T extends string[], U extends T>(k0: keyof T, k1: keyof [...T], k2: keyof [...U], k3: keyof [1, 2, ...T]): void;
709+
declare function ft16<T extends [unknown]>(x: [unknown, unknown], y: [...T, ...T]): void;
710+
declare function ft17<T extends [] | [unknown]>(x: [unknown, unknown], y: [...T, ...T]): void;
711+
declare function ft18<T extends unknown[]>(x: [unknown, unknown], y: [...T, ...T]): void;
685712
type First<T extends readonly unknown[]> = T extends readonly [unknown, ...unknown[]] ? T[0] : T[0] | undefined;
686713
type DropFirst<T extends readonly unknown[]> = T extends readonly [unknown?, ...infer U] ? U : [...T];
687714
type Last<T extends readonly unknown[]> = T extends readonly [...unknown[], infer U] ? U : T extends readonly [unknown, ...unknown[]] ? T[number] : T[number] | undefined;

0 commit comments

Comments
 (0)