Skip to content

Commit 6d38c6b

Browse files
allow extracting rest parameters' passed types into generics
1 parent bab287d commit 6d38c6b

23 files changed

+377
-128
lines changed

src/compiler/checker.ts

Lines changed: 76 additions & 28 deletions
Large diffs are not rendered by default.

tests/baselines/reference/FunctionDeclaration10_es6.errors.txt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,17 @@
11
tests/cases/conformance/es6/functionDeclarations/FunctionDeclaration10_es6.ts(1,16): error TS2371: A parameter initializer is only allowed in a function or constructor implementation.
2+
tests/cases/conformance/es6/functionDeclarations/FunctionDeclaration10_es6.ts(1,20): error TS2523: 'yield' expressions cannot be used in a parameter initializer.
23
tests/cases/conformance/es6/functionDeclarations/FunctionDeclaration10_es6.ts(1,26): error TS1005: ',' expected.
34
tests/cases/conformance/es6/functionDeclarations/FunctionDeclaration10_es6.ts(1,29): error TS1138: Parameter declaration expected.
45
tests/cases/conformance/es6/functionDeclarations/FunctionDeclaration10_es6.ts(1,29): error TS2304: Cannot find name 'yield'.
56
tests/cases/conformance/es6/functionDeclarations/FunctionDeclaration10_es6.ts(1,34): error TS1005: ';' expected.
67

78

8-
==== tests/cases/conformance/es6/functionDeclarations/FunctionDeclaration10_es6.ts (5 errors) ====
9+
==== tests/cases/conformance/es6/functionDeclarations/FunctionDeclaration10_es6.ts (6 errors) ====
910
function * foo(a = yield => yield) {
1011
~~~~~~~~~
1112
!!! error TS2371: A parameter initializer is only allowed in a function or constructor implementation.
13+
~~~~~
14+
!!! error TS2523: 'yield' expressions cannot be used in a parameter initializer.
1215
~~
1316
!!! error TS1005: ',' expected.
1417
~~~~~

tests/baselines/reference/asyncFunctionDeclaration10_es2017.errors.txt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
tests/cases/conformance/async/es2017/functionDeclarations/asyncFunctionDeclaration10_es2017.ts(1,20): error TS2371: A parameter initializer is only allowed in a function or constructor implementation.
2+
tests/cases/conformance/async/es2017/functionDeclarations/asyncFunctionDeclaration10_es2017.ts(1,24): error TS2524: 'await' expressions cannot be used in a parameter initializer.
23
tests/cases/conformance/async/es2017/functionDeclarations/asyncFunctionDeclaration10_es2017.ts(1,30): error TS1109: Expression expected.
34
tests/cases/conformance/async/es2017/functionDeclarations/asyncFunctionDeclaration10_es2017.ts(1,33): error TS1138: Parameter declaration expected.
45
tests/cases/conformance/async/es2017/functionDeclarations/asyncFunctionDeclaration10_es2017.ts(1,33): error TS2304: Cannot find name 'await'.
@@ -8,10 +9,12 @@ tests/cases/conformance/async/es2017/functionDeclarations/asyncFunctionDeclarati
89
tests/cases/conformance/async/es2017/functionDeclarations/asyncFunctionDeclaration10_es2017.ts(1,53): error TS1109: Expression expected.
910

1011

11-
==== tests/cases/conformance/async/es2017/functionDeclarations/asyncFunctionDeclaration10_es2017.ts (8 errors) ====
12+
==== tests/cases/conformance/async/es2017/functionDeclarations/asyncFunctionDeclaration10_es2017.ts (9 errors) ====
1213
async function foo(a = await => await): Promise<void> {
1314
~~~~~~~~~
1415
!!! error TS2371: A parameter initializer is only allowed in a function or constructor implementation.
16+
~~~~~
17+
!!! error TS2524: 'await' expressions cannot be used in a parameter initializer.
1518
~~
1619
!!! error TS1109: Expression expected.
1720
~~~~~

tests/baselines/reference/asyncFunctionDeclaration10_es5.errors.txt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
tests/cases/conformance/async/es5/functionDeclarations/asyncFunctionDeclaration10_es5.ts(1,20): error TS2371: A parameter initializer is only allowed in a function or constructor implementation.
2+
tests/cases/conformance/async/es5/functionDeclarations/asyncFunctionDeclaration10_es5.ts(1,24): error TS2524: 'await' expressions cannot be used in a parameter initializer.
23
tests/cases/conformance/async/es5/functionDeclarations/asyncFunctionDeclaration10_es5.ts(1,30): error TS1109: Expression expected.
34
tests/cases/conformance/async/es5/functionDeclarations/asyncFunctionDeclaration10_es5.ts(1,33): error TS1138: Parameter declaration expected.
45
tests/cases/conformance/async/es5/functionDeclarations/asyncFunctionDeclaration10_es5.ts(1,33): error TS2304: Cannot find name 'await'.
@@ -8,10 +9,12 @@ tests/cases/conformance/async/es5/functionDeclarations/asyncFunctionDeclaration1
89
tests/cases/conformance/async/es5/functionDeclarations/asyncFunctionDeclaration10_es5.ts(1,53): error TS1109: Expression expected.
910

1011

11-
==== tests/cases/conformance/async/es5/functionDeclarations/asyncFunctionDeclaration10_es5.ts (8 errors) ====
12+
==== tests/cases/conformance/async/es5/functionDeclarations/asyncFunctionDeclaration10_es5.ts (9 errors) ====
1213
async function foo(a = await => await): Promise<void> {
1314
~~~~~~~~~
1415
!!! error TS2371: A parameter initializer is only allowed in a function or constructor implementation.
16+
~~~~~
17+
!!! error TS2524: 'await' expressions cannot be used in a parameter initializer.
1518
~~
1619
!!! error TS1109: Expression expected.
1720
~~~~~

tests/baselines/reference/asyncFunctionDeclaration10_es6.errors.txt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
tests/cases/conformance/async/es6/functionDeclarations/asyncFunctionDeclaration10_es6.ts(1,20): error TS2371: A parameter initializer is only allowed in a function or constructor implementation.
2+
tests/cases/conformance/async/es6/functionDeclarations/asyncFunctionDeclaration10_es6.ts(1,24): error TS2524: 'await' expressions cannot be used in a parameter initializer.
23
tests/cases/conformance/async/es6/functionDeclarations/asyncFunctionDeclaration10_es6.ts(1,30): error TS1109: Expression expected.
34
tests/cases/conformance/async/es6/functionDeclarations/asyncFunctionDeclaration10_es6.ts(1,33): error TS1138: Parameter declaration expected.
45
tests/cases/conformance/async/es6/functionDeclarations/asyncFunctionDeclaration10_es6.ts(1,33): error TS2304: Cannot find name 'await'.
@@ -8,10 +9,12 @@ tests/cases/conformance/async/es6/functionDeclarations/asyncFunctionDeclaration1
89
tests/cases/conformance/async/es6/functionDeclarations/asyncFunctionDeclaration10_es6.ts(1,53): error TS1109: Expression expected.
910

1011

11-
==== tests/cases/conformance/async/es6/functionDeclarations/asyncFunctionDeclaration10_es6.ts (8 errors) ====
12+
==== tests/cases/conformance/async/es6/functionDeclarations/asyncFunctionDeclaration10_es6.ts (9 errors) ====
1213
async function foo(a = await => await): Promise<void> {
1314
~~~~~~~~~
1415
!!! error TS2371: A parameter initializer is only allowed in a function or constructor implementation.
16+
~~~~~
17+
!!! error TS2524: 'await' expressions cannot be used in a parameter initializer.
1518
~~
1619
!!! error TS1109: Expression expected.
1720
~~~~~
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
//// [destructureGenerics.ts]
2+
declare function f<T extends any[]>(...args: T): T;
3+
var x = f(1,2);
4+
var x: [1, 2];
5+
declare function g<T extends [number, number]>(...args: T): T;
6+
var z = g(1,2);
7+
var z: [1,2];
8+
declare function h<T>(...args: T[]): T;
9+
var b = h(1,2,3);
10+
var b: number;
11+
12+
13+
//// [destructureGenerics.js]
14+
var x = f(1, 2);
15+
var x;
16+
var z = g(1, 2);
17+
var z;
18+
var b = h(1, 2, 3);
19+
var b;
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
=== tests/cases/compiler/destructureGenerics.ts ===
2+
declare function f<T extends any[]>(...args: T): T;
3+
>f : Symbol(f, Decl(destructureGenerics.ts, 0, 0))
4+
>T : Symbol(T, Decl(destructureGenerics.ts, 0, 19))
5+
>args : Symbol(args, Decl(destructureGenerics.ts, 0, 36))
6+
>T : Symbol(T, Decl(destructureGenerics.ts, 0, 19))
7+
>T : Symbol(T, Decl(destructureGenerics.ts, 0, 19))
8+
9+
var x = f(1,2);
10+
>x : Symbol(x, Decl(destructureGenerics.ts, 1, 3), Decl(destructureGenerics.ts, 2, 3))
11+
>f : Symbol(f, Decl(destructureGenerics.ts, 0, 0))
12+
13+
var x: [1, 2];
14+
>x : Symbol(x, Decl(destructureGenerics.ts, 1, 3), Decl(destructureGenerics.ts, 2, 3))
15+
16+
declare function g<T extends [number, number]>(...args: T): T;
17+
>g : Symbol(g, Decl(destructureGenerics.ts, 2, 14))
18+
>T : Symbol(T, Decl(destructureGenerics.ts, 3, 19))
19+
>args : Symbol(args, Decl(destructureGenerics.ts, 3, 47))
20+
>T : Symbol(T, Decl(destructureGenerics.ts, 3, 19))
21+
>T : Symbol(T, Decl(destructureGenerics.ts, 3, 19))
22+
23+
var z = g(1,2);
24+
>z : Symbol(z, Decl(destructureGenerics.ts, 4, 3), Decl(destructureGenerics.ts, 5, 3))
25+
>g : Symbol(g, Decl(destructureGenerics.ts, 2, 14))
26+
27+
var z: [1,2];
28+
>z : Symbol(z, Decl(destructureGenerics.ts, 4, 3), Decl(destructureGenerics.ts, 5, 3))
29+
30+
declare function h<T>(...args: T[]): T;
31+
>h : Symbol(h, Decl(destructureGenerics.ts, 5, 13))
32+
>T : Symbol(T, Decl(destructureGenerics.ts, 6, 19))
33+
>args : Symbol(args, Decl(destructureGenerics.ts, 6, 22))
34+
>T : Symbol(T, Decl(destructureGenerics.ts, 6, 19))
35+
>T : Symbol(T, Decl(destructureGenerics.ts, 6, 19))
36+
37+
var b = h(1,2,3);
38+
>b : Symbol(b, Decl(destructureGenerics.ts, 7, 3), Decl(destructureGenerics.ts, 8, 3))
39+
>h : Symbol(h, Decl(destructureGenerics.ts, 5, 13))
40+
41+
var b: number;
42+
>b : Symbol(b, Decl(destructureGenerics.ts, 7, 3), Decl(destructureGenerics.ts, 8, 3))
43+
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
=== tests/cases/compiler/destructureGenerics.ts ===
2+
declare function f<T extends any[]>(...args: T): T;
3+
>f : <T extends any[]>(...args: T) => T
4+
>T : T
5+
>args : T
6+
>T : T
7+
>T : T
8+
9+
var x = f(1,2);
10+
>x : [1, 2]
11+
>f(1,2) : [1, 2]
12+
>f : <T extends any[]>(...args: T) => T
13+
>1 : 1
14+
>2 : 2
15+
16+
var x: [1, 2];
17+
>x : [1, 2]
18+
19+
declare function g<T extends [number, number]>(...args: T): T;
20+
>g : <T extends [number, number]>(...args: T) => T
21+
>T : T
22+
>args : T
23+
>T : T
24+
>T : T
25+
26+
var z = g(1,2);
27+
>z : [1, 2]
28+
>g(1,2) : [1, 2]
29+
>g : <T extends [number, number]>(...args: T) => T
30+
>1 : 1
31+
>2 : 2
32+
33+
var z: [1,2];
34+
>z : [1, 2]
35+
36+
declare function h<T>(...args: T[]): T;
37+
>h : <T>(...args: T[]) => T
38+
>T : T
39+
>args : T[]
40+
>T : T
41+
>T : T
42+
43+
var b = h(1,2,3);
44+
>b : number
45+
>h(1,2,3) : 1 | 2 | 3
46+
>h : <T>(...args: T[]) => T
47+
>1 : 1
48+
>2 : 2
49+
>3 : 3
50+
51+
var b: number;
52+
>b : number
53+
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
tests/cases/compiler/destructureGenericsErrors.ts(2,9): error TS2554: Expected 2 arguments, but got 1.
2+
tests/cases/compiler/destructureGenericsErrors.ts(4,9): error TS2554: Expected 2 arguments, but got 3.
3+
4+
5+
==== tests/cases/compiler/destructureGenericsErrors.ts (2 errors) ====
6+
declare function g<T extends [number, number]>(...args: T): T;
7+
var y = g(1); // error
8+
~~~~
9+
!!! error TS2554: Expected 2 arguments, but got 1.
10+
var y: [1];
11+
var a = g(1,2,3); // error
12+
~~~~~~~~
13+
!!! error TS2554: Expected 2 arguments, but got 3.
14+
var a: [1,2,3];
15+
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
//// [destructureGenericsErrors.ts]
2+
declare function g<T extends [number, number]>(...args: T): T;
3+
var y = g(1); // error
4+
var y: [1];
5+
var a = g(1,2,3); // error
6+
var a: [1,2,3];
7+
8+
9+
//// [destructureGenericsErrors.js]
10+
var y = g(1); // error
11+
var y;
12+
var a = g(1, 2, 3); // error
13+
var a;

0 commit comments

Comments
 (0)