Skip to content

Commit 9b6de0c

Browse files
tests
1 parent d65d9b2 commit 9b6de0c

21 files changed

+537
-77
lines changed

src/compiler/checker.ts

+10-8
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
/// <reference path="moduleNameResolver.ts"/>
22
/// <reference path="binder.ts"/>
33
/// <reference path="symbolWalker.ts" />
4-
// /// <reference types="node"/>
5-
// declare var console: Console;
64

75
/* @internal */
86
namespace ts {
@@ -6615,17 +6613,19 @@ namespace ts {
66156613
return getTypeOfSymbol(lastOrUndefined(signature.parameters));
66166614
}
66176615

6618-
function getRestTypeOfSignature(signature: Signature, pos: number): Type {
6616+
function getRestTypeOfSignature(signature: Signature, pos?: number): Type {
66196617
const arrIdx = pos - (signature.parameters.length - 1);
66206618
if (signature.hasRestParameter) {
66216619
const type = getRestConstraintOfSignature(signature);
66226620
if (isArrayType(type)) {
66236621
return (<TypeReference>type).typeArguments[0];
66246622
}
6623+
else if (isTupleLikeType(type)) {
6624+
const symbol = getPropertyOfObjectType(getApparentType(type), arrIdx + "" as __String);
6625+
return symbol ? getIndexedAccessType(type, pos !== undefined ? getLiteralType(arrIdx) : globalNumberType) : neverType;
6626+
}
66256627
else if (isArrayLikeType(type)) {
6626-
return getIndexedAccessType(type, getLiteralType(arrIdx));
6627-
// const symbol = getPropertyOfObjectType(getApparentType(type), arrIdx + "" as __String);
6628-
// return symbol ? getIndexedAccessType(type, getLiteralType(arrIdx)) : neverType;
6628+
return getIndexedAccessType(type, pos !== undefined ? getLiteralType(arrIdx) : globalNumberType);
66296629
}
66306630
}
66316631
return anyType;
@@ -10671,7 +10671,8 @@ namespace ts {
1067110671
if (type === inference.typeParameter) {
1067210672
return inference;
1067310673
}
10674-
else if ((type as IndexedAccessType).objectType === inference.typeParameter) {
10674+
else if ((type as IndexedAccessType).objectType === inference.typeParameter &&
10675+
isTypeInstanceOf((type as IndexedAccessType).indexType, globalNumberType)) {
1067510676
return inference;
1067610677
}
1067710678
}
@@ -18225,7 +18226,8 @@ namespace ts {
1822518226

1822618227
// Only check rest parameter type if it's not a binding pattern. Since binding patterns are
1822718228
// not allowed in a rest parameter, we already have an error from checkGrammarParameterList.
18228-
if (node.dotDotDotToken && !isBindingPattern(node.name) && !isArrayLikeType(getTypeOfSymbol(node.symbol))) {
18229+
const type = getTypeOfSymbol(node.symbol);
18230+
if (node.dotDotDotToken && !isBindingPattern(node.name) && (!isArrayLikeType(type) || type === anyType)) {
1822918231
error(node, Diagnostics.A_rest_parameter_must_be_of_an_array_type);
1823018232
}
1823118233
}

tests/baselines/reference/FunctionDeclaration10_es6.errors.txt

+4-1
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

+4-1
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

+4-1
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

+4-1
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
~~~~~

tests/baselines/reference/destructureGenerics.errors.txt

-20
This file was deleted.

tests/baselines/reference/destructureGenerics.js

-8
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,8 @@ declare function f<T extends any[]>(...args: T): T;
33
var x = f(1,2);
44
var x: [1, 2];
55
declare function g<T extends [number, number]>(...args: T): T;
6-
var y = g(1); // error
7-
var y: [1];
86
var z = g(1,2);
97
var z: [1,2];
10-
var a = g(1,2,3); // error
11-
var a: [1,2,3];
128
declare function h<T>(...args: T[]): T;
139
var b = h(1,2,3);
1410
var b: number;
@@ -17,11 +13,7 @@ var b: number;
1713
//// [destructureGenerics.js]
1814
var x = f(1, 2);
1915
var x;
20-
var y = g(1); // error
21-
var y;
2216
var z = g(1, 2);
2317
var z;
24-
var a = g(1, 2, 3); // error
25-
var a;
2618
var b = h(1, 2, 3);
2719
var b;
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,43 @@
11
=== tests/cases/compiler/destructureGenerics.ts ===
2-
// declare function f<T extends any[]>(...args: T): T;
3-
// var x = f(1,2);
4-
// var x: number[];
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+
516
declare function g<T extends [number, number]>(...args: T): T;
6-
>g : Symbol(g, Decl(destructureGenerics.ts, 0, 0))
17+
>g : Symbol(g, Decl(destructureGenerics.ts, 2, 14))
718
>T : Symbol(T, Decl(destructureGenerics.ts, 3, 19))
819
>args : Symbol(args, Decl(destructureGenerics.ts, 3, 47))
920
>T : Symbol(T, Decl(destructureGenerics.ts, 3, 19))
1021
>T : Symbol(T, Decl(destructureGenerics.ts, 3, 19))
1122

12-
// var y = g(1); // error
13-
// var y: [1];
1423
var z = g(1,2);
15-
>z : Symbol(z, Decl(destructureGenerics.ts, 6, 3))
16-
>g : Symbol(g, Decl(destructureGenerics.ts, 0, 0))
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))
1729

18-
// var z: [1,2];
19-
// var a = g(1,2,3); // error
20-
// var a: [1,2,3];
2130
declare function h<T>(...args: T[]): T;
22-
>h : Symbol(h, Decl(destructureGenerics.ts, 6, 15))
23-
>T : Symbol(T, Decl(destructureGenerics.ts, 10, 19))
24-
>args : Symbol(args, Decl(destructureGenerics.ts, 10, 22))
25-
>T : Symbol(T, Decl(destructureGenerics.ts, 10, 19))
26-
>T : Symbol(T, Decl(destructureGenerics.ts, 10, 19))
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))
2736

2837
var b = h(1,2,3);
29-
>b : Symbol(b, Decl(destructureGenerics.ts, 11, 3))
30-
>h : Symbol(h, Decl(destructureGenerics.ts, 6, 15))
38+
>b : Symbol(b, Decl(destructureGenerics.ts, 7, 3), Decl(destructureGenerics.ts, 8, 3))
39+
>h : Symbol(h, Decl(destructureGenerics.ts, 5, 13))
3140

32-
// var b: 1|2|3;
41+
var b: number;
42+
>b : Symbol(b, Decl(destructureGenerics.ts, 7, 3), Decl(destructureGenerics.ts, 8, 3))
3343

Original file line numberDiff line numberDiff line change
@@ -1,26 +1,38 @@
11
=== tests/cases/compiler/destructureGenerics.ts ===
2-
// declare function f<T extends any[]>(...args: T): T;
3-
// var x = f(1,2);
4-
// var x: number[];
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+
519
declare function g<T extends [number, number]>(...args: T): T;
620
>g : <T extends [number, number]>(...args: T) => T
721
>T : T
822
>args : T
923
>T : T
1024
>T : T
1125

12-
// var y = g(1); // error
13-
// var y: [1];
1426
var z = g(1,2);
1527
>z : [1, 2]
1628
>g(1,2) : [1, 2]
1729
>g : <T extends [number, number]>(...args: T) => T
1830
>1 : 1
1931
>2 : 2
2032

21-
// var z: [1,2];
22-
// var a = g(1,2,3); // error
23-
// var a: [1,2,3];
33+
var z: [1,2];
34+
>z : [1, 2]
35+
2436
declare function h<T>(...args: T[]): T;
2537
>h : <T>(...args: T[]) => T
2638
>T : T
@@ -36,5 +48,6 @@ var b = h(1,2,3);
3648
>2 : 2
3749
>3 : 3
3850

39-
// var b: 1|2|3;
51+
var b: number;
52+
>b : number
4053

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,15): error TS2345: Argument of type '3' is not assignable to parameter of type 'never'.
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 TS2345: Argument of type '3' is not assignable to parameter of type 'never'.
14+
var a: [1,2,3];
15+
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;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
=== tests/cases/compiler/destructureGenericsErrors.ts ===
2+
declare function g<T extends [number, number]>(...args: T): T;
3+
>g : Symbol(g, Decl(destructureGenericsErrors.ts, 0, 0))
4+
>T : Symbol(T, Decl(destructureGenericsErrors.ts, 0, 19))
5+
>args : Symbol(args, Decl(destructureGenericsErrors.ts, 0, 47))
6+
>T : Symbol(T, Decl(destructureGenericsErrors.ts, 0, 19))
7+
>T : Symbol(T, Decl(destructureGenericsErrors.ts, 0, 19))
8+
9+
// var y = g(1); // error
10+
// var y: [1];
11+
var a = g(1,2,3); // error
12+
>a : Symbol(a, Decl(destructureGenericsErrors.ts, 3, 3), Decl(destructureGenericsErrors.ts, 4, 3))
13+
>g : Symbol(g, Decl(destructureGenericsErrors.ts, 0, 0))
14+
15+
var a: [1,2,3];
16+
>a : Symbol(a, Decl(destructureGenericsErrors.ts, 3, 3), Decl(destructureGenericsErrors.ts, 4, 3))
17+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
=== tests/cases/compiler/destructureGenericsErrors.ts ===
2+
declare function g<T extends [number, number]>(...args: T): T;
3+
>g : <T extends [number, number]>(...args: T) => T
4+
>T : T
5+
>args : T
6+
>T : T
7+
>T : T
8+
9+
// var y = g(1); // error
10+
// var y: [1];
11+
var a = g(1,2,3); // error
12+
>a : [1, 2, 3]
13+
>g(1,2,3) : [1, 2, 3]
14+
>g : <T extends [number, number]>(...args: T) => T
15+
>1 : 1
16+
>2 : 2
17+
>3 : 3
18+
19+
var a: [1,2,3];
20+
>a : [1, 2, 3]
21+

tests/baselines/reference/mappedTypeErrors.errors.txt

+8-1
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@ tests/cases/conformance/types/mapped/mappedTypeErrors.ts(77,59): error TS2345: A
2626
Object literal may only specify known properties, and 'z' does not exist in type 'Readonly<{ x: number; y: number; }>'.
2727
tests/cases/conformance/types/mapped/mappedTypeErrors.ts(83,58): error TS2345: Argument of type '{ x: number; y: number; z: number; }' is not assignable to parameter of type 'Partial<{ x: number; y: number; }>'.
2828
Object literal may only specify known properties, and 'z' does not exist in type 'Partial<{ x: number; y: number; }>'.
29+
tests/cases/conformance/types/mapped/mappedTypeErrors.ts(105,15): error TS2345: Argument of type '{ a: undefined; }' is not assignable to parameter of type 'Pick<Foo, "a">'.
30+
Types of property 'a' are incompatible.
31+
Type 'undefined' is not assignable to type 'string'.
2932
tests/cases/conformance/types/mapped/mappedTypeErrors.ts(106,17): error TS2345: Argument of type '{ c: boolean; }' is not assignable to parameter of type 'Pick<Foo, "a" | "b">'.
3033
Object literal may only specify known properties, and 'c' does not exist in type 'Pick<Foo, "a" | "b">'.
3134
tests/cases/conformance/types/mapped/mappedTypeErrors.ts(123,12): error TS2345: Argument of type '{ a: undefined; }' is not assignable to parameter of type 'Pick<Foo, "a">'.
@@ -46,7 +49,7 @@ tests/cases/conformance/types/mapped/mappedTypeErrors.ts(136,16): error TS2322:
4649
tests/cases/conformance/types/mapped/mappedTypeErrors.ts(136,21): error TS2536: Type 'P' cannot be used to index type 'T'.
4750

4851

49-
==== tests/cases/conformance/types/mapped/mappedTypeErrors.ts (25 errors) ====
52+
==== tests/cases/conformance/types/mapped/mappedTypeErrors.ts (26 errors) ====
5053
interface Shape {
5154
name: string;
5255
width: number;
@@ -197,6 +200,10 @@ tests/cases/conformance/types/mapped/mappedTypeErrors.ts(136,21): error TS2536:
197200
setState(foo, { });
198201
setState(foo, foo);
199202
setState(foo, { a: undefined }); // Error
203+
~~~~~~~~~~~~~~~~
204+
!!! error TS2345: Argument of type '{ a: undefined; }' is not assignable to parameter of type 'Pick<Foo, "a">'.
205+
!!! error TS2345: Types of property 'a' are incompatible.
206+
!!! error TS2345: Type 'undefined' is not assignable to type 'string'.
200207
setState(foo, { c: true }); // Error
201208
~~~~~~~
202209
!!! error TS2345: Argument of type '{ c: boolean; }' is not assignable to parameter of type 'Pick<Foo, "a" | "b">'.

0 commit comments

Comments
 (0)