Skip to content

Commit 3bca716

Browse files
committed
Add test
1 parent 60992ca commit 3bca716

File tree

5 files changed

+583
-513
lines changed

5 files changed

+583
-513
lines changed

tests/baselines/reference/variadicTuples1.errors.txt

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,26 @@
11
tests/cases/conformance/types/tuple/variadicTuples1.ts(6,48): error TS1256: A rest element must be last in a tuple type.
2-
tests/cases/conformance/types/tuple/variadicTuples1.ts(46,5): error TS2555: Expected at least 3 arguments, but got 2.
3-
tests/cases/conformance/types/tuple/variadicTuples1.ts(47,17): error TS2345: Argument of type '45' is not assignable to parameter of type 'boolean'.
4-
tests/cases/conformance/types/tuple/variadicTuples1.ts(125,9): error TS2344: Type 'V' does not satisfy the constraint 'unknown[]'.
2+
tests/cases/conformance/types/tuple/variadicTuples1.ts(52,5): error TS2555: Expected at least 3 arguments, but got 2.
3+
tests/cases/conformance/types/tuple/variadicTuples1.ts(53,17): error TS2345: Argument of type '45' is not assignable to parameter of type 'boolean'.
4+
tests/cases/conformance/types/tuple/variadicTuples1.ts(131,9): error TS2344: Type 'V' does not satisfy the constraint 'unknown[]'.
55
The type 'readonly unknown[]' is 'readonly' and cannot be assigned to the mutable type 'unknown[]'.
6-
tests/cases/conformance/types/tuple/variadicTuples1.ts(143,5): error TS2322: Type '[string, ...unknown[]]' is not assignable to type '[string, ...T]'.
6+
tests/cases/conformance/types/tuple/variadicTuples1.ts(149,5): error TS2322: Type '[string, ...unknown[]]' is not assignable to type '[string, ...T]'.
77
Target requires 2 element(s) but source may have fewer.
8-
tests/cases/conformance/types/tuple/variadicTuples1.ts(145,5): error TS2322: Type '[string, ...unknown[]]' is not assignable to type '[string, ...U]'.
8+
tests/cases/conformance/types/tuple/variadicTuples1.ts(151,5): error TS2322: Type '[string, ...unknown[]]' is not assignable to type '[string, ...U]'.
99
Target requires 2 element(s) but source may have fewer.
10-
tests/cases/conformance/types/tuple/variadicTuples1.ts(146,5): error TS2322: Type '[string, ...T]' is not assignable to type '[string, ...U]'.
10+
tests/cases/conformance/types/tuple/variadicTuples1.ts(152,5): error TS2322: Type '[string, ...T]' is not assignable to type '[string, ...U]'.
1111
Type 'T' is not assignable to type 'U'.
1212
'T' is assignable to the constraint of type 'U', but 'U' could be instantiated with a different subtype of constraint 'string[]'.
1313
Type 'string[]' is not assignable to type 'U'.
1414
'U' could be instantiated with an arbitrary type which could be unrelated to 'string[]'.
15-
tests/cases/conformance/types/tuple/variadicTuples1.ts(154,5): error TS2322: Type 'readonly [...T]' is not assignable to type 'T'.
15+
tests/cases/conformance/types/tuple/variadicTuples1.ts(160,5): error TS2322: Type 'readonly [...T]' is not assignable to type 'T'.
1616
'T' could be instantiated with an arbitrary type which could be unrelated to 'readonly [...T]'.
17-
tests/cases/conformance/types/tuple/variadicTuples1.ts(156,5): error TS4104: The type 'readonly [...T]' is 'readonly' and cannot be assigned to the mutable type '[...T]'.
18-
tests/cases/conformance/types/tuple/variadicTuples1.ts(163,5): error TS2322: Type 'readonly [...T]' is not assignable to type 'T'.
17+
tests/cases/conformance/types/tuple/variadicTuples1.ts(162,5): error TS4104: The type 'readonly [...T]' is 'readonly' and cannot be assigned to the mutable type '[...T]'.
18+
tests/cases/conformance/types/tuple/variadicTuples1.ts(169,5): error TS2322: Type 'readonly [...T]' is not assignable to type 'T'.
1919
'readonly [...T]' is assignable to the constraint of type 'T', but 'T' could be instantiated with a different subtype of constraint 'readonly unknown[]'.
20-
tests/cases/conformance/types/tuple/variadicTuples1.ts(164,5): error TS2322: Type 'T' is not assignable to type '[...T]'.
20+
tests/cases/conformance/types/tuple/variadicTuples1.ts(170,5): error TS2322: Type 'T' is not assignable to type '[...T]'.
2121
The type 'readonly unknown[]' is 'readonly' and cannot be assigned to the mutable type '[...T]'.
22-
tests/cases/conformance/types/tuple/variadicTuples1.ts(165,5): error TS4104: The type 'readonly [...T]' is 'readonly' and cannot be assigned to the mutable type '[...T]'.
23-
tests/cases/conformance/types/tuple/variadicTuples1.ts(297,14): error TS7019: Rest parameter 'x' implicitly has an 'any[]' type.
22+
tests/cases/conformance/types/tuple/variadicTuples1.ts(171,5): error TS4104: The type 'readonly [...T]' is 'readonly' and cannot be assigned to the mutable type '[...T]'.
23+
tests/cases/conformance/types/tuple/variadicTuples1.ts(303,14): error TS7019: Rest parameter 'x' implicitly has an 'any[]' type.
2424

2525

2626
==== tests/cases/conformance/types/tuple/variadicTuples1.ts (13 errors) ====
@@ -62,6 +62,12 @@ tests/cases/conformance/types/tuple/variadicTuples1.ts(297,14): error TS7019: Re
6262
const tc3 = concat([1, 2, 3], sa);
6363
const tc4 = concat(sa, [1, 2, 3]); // Ideally would be [...string[], number, number, number]
6464

65+
function concat2<T extends readonly unknown[], U extends readonly unknown[]>(t: T, u: U) {
66+
return [...t, ...u]; // (T[number] | U[number])[]
67+
}
68+
69+
const tc5 = concat2([1, 2, 3] as const, [4, 5, 6] as const); // (1 | 2 | 3 | 4 | 5 | 6)[]
70+
6571
// Spread arguments
6672

6773
declare function foo1(a: number, b: string, c: boolean, ...d: number[]): void;
@@ -74,7 +80,7 @@ tests/cases/conformance/types/tuple/variadicTuples1.ts(297,14): error TS7019: Re
7480
foo1(...t1); // Error
7581
~~~~~~~~~~~
7682
!!! error TS2555: Expected at least 3 arguments, but got 2.
77-
!!! related TS6210 tests/cases/conformance/types/tuple/variadicTuples1.ts:39:45: An argument for 'c' was not provided.
83+
!!! related TS6210 tests/cases/conformance/types/tuple/variadicTuples1.ts:45:45: An argument for 'c' was not provided.
7884
foo1(...t1, 45); // Error
7985
~~
8086
!!! error TS2345: Argument of type '45' is not assignable to parameter of type 'boolean'.

tests/baselines/reference/variadicTuples1.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,12 @@ const tc2 = concat(['hello'], [42]);
3535
const tc3 = concat([1, 2, 3], sa);
3636
const tc4 = concat(sa, [1, 2, 3]); // Ideally would be [...string[], number, number, number]
3737

38+
function concat2<T extends readonly unknown[], U extends readonly unknown[]>(t: T, u: U) {
39+
return [...t, ...u]; // (T[number] | U[number])[]
40+
}
41+
42+
const tc5 = concat2([1, 2, 3] as const, [4, 5, 6] as const); // (1 | 2 | 3 | 4 | 5 | 6)[]
43+
3844
// Spread arguments
3945

4046
declare function foo1(a: number, b: string, c: boolean, ...d: number[]): void;
@@ -320,6 +326,10 @@ var tc1 = concat([], []);
320326
var tc2 = concat(['hello'], [42]);
321327
var tc3 = concat([1, 2, 3], sa);
322328
var tc4 = concat(sa, [1, 2, 3]); // Ideally would be [...string[], number, number, number]
329+
function concat2(t, u) {
330+
return __spreadArrays(t, u); // (T[number] | U[number])[]
331+
}
332+
var tc5 = concat2([1, 2, 3], [4, 5, 6]); // (1 | 2 | 3 | 4 | 5 | 6)[]
323333
function foo2(t1, t2, a1) {
324334
foo1(1, 'abc', true, 42, 43, 44);
325335
foo1.apply(void 0, __spreadArrays(t1, [true, 42, 43, 44]));
@@ -483,6 +493,8 @@ declare const tc1: [];
483493
declare const tc2: [string, number];
484494
declare const tc3: [number, number, number, ...string[]];
485495
declare const tc4: (string | number)[];
496+
declare function concat2<T extends readonly unknown[], U extends readonly unknown[]>(t: T, u: U): (T[number] | U[number])[];
497+
declare const tc5: (2 | 4 | 1 | 3 | 6 | 5)[];
486498
declare function foo1(a: number, b: string, c: boolean, ...d: number[]): void;
487499
declare function foo2(t1: [number, string], t2: [boolean], a1: number[]): void;
488500
declare function foo3<T extends unknown[]>(x: number, ...args: [...T, number]): T;

0 commit comments

Comments
 (0)