Skip to content

Commit 966e697

Browse files
committed
Compiler test case for usage of contextual rest parameter
1 parent b405045 commit 966e697

File tree

3 files changed

+44
-0
lines changed

3 files changed

+44
-0
lines changed
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
tests/cases/compiler/contextuallyTypingRestParameters.ts(3,9): error TS2323: Type 'string[]' is not assignable to type 'string'.
2+
tests/cases/compiler/contextuallyTypingRestParameters.ts(5,9): error TS2323: Type 'string[]' is not assignable to type 'string'.
3+
4+
5+
==== tests/cases/compiler/contextuallyTypingRestParameters.ts (2 errors) ====
6+
var x: (...y: string[]) => void = function (.../*3*/y) {
7+
var t = y;
8+
var x2: string = t; // This should be error
9+
~~
10+
!!! error TS2323: Type 'string[]' is not assignable to type 'string'.
11+
var x3: string[] = t; // No error
12+
var y2: string = y; // This should be error
13+
~~
14+
!!! error TS2323: Type 'string[]' is not assignable to type 'string'.
15+
var y3: string[] = y; // No error
16+
};
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
//// [contextuallyTypingRestParameters.ts]
2+
var x: (...y: string[]) => void = function (.../*3*/y) {
3+
var t = y;
4+
var x2: string = t; // This should be error
5+
var x3: string[] = t; // No error
6+
var y2: string = y; // This should be error
7+
var y3: string[] = y; // No error
8+
};
9+
10+
//// [contextuallyTypingRestParameters.js]
11+
var x = function () {
12+
var y = [];
13+
for (var _i = 0; _i < arguments.length; _i++) {
14+
y[_i - 0] = arguments[_i];
15+
}
16+
var t = y;
17+
var x2 = t; // This should be error
18+
var x3 = t; // No error
19+
var y2 = y; // This should be error
20+
var y3 = y; // No error
21+
};
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
var x: (...y: string[]) => void = function (.../*3*/y) {
2+
var t = y;
3+
var x2: string = t; // This should be error
4+
var x3: string[] = t; // No error
5+
var y2: string = y; // This should be error
6+
var y3: string[] = y; // No error
7+
};

0 commit comments

Comments
 (0)