Skip to content

Commit ca92653

Browse files
committed
Addressing CR feedback
1 parent 95b3d6b commit ca92653

File tree

4 files changed

+56
-8
lines changed

4 files changed

+56
-8
lines changed

src/compiler/checker.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1721,7 +1721,7 @@ module ts {
17211721
}
17221722
}
17231723
else {
1724-
// For an array binding element the specified or inferred type of the parent must be assignable to any[]
1724+
// For an array binding element the specified or inferred type of the parent must be an array-like type
17251725
if (!isArrayLikeType(parentType)) {
17261726
error(pattern, Diagnostics.Type_0_is_not_an_array_type, typeToString(parentType));
17271727
return unknownType;
@@ -4191,6 +4191,7 @@ module ts {
41914191
}
41924192

41934193
function isArrayLikeType(type: Type): boolean {
4194+
// A type is array-like if it is not the undefined or null type and if it is assignable to any[]
41944195
return !(type.flags & (TypeFlags.Undefined | TypeFlags.Null)) && isTypeAssignableTo(type, anyArrayType);
41954196
}
41964197

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,24 @@
1-
tests/cases/conformance/es6/destructuring/restElementWithNullInitializer.ts(1,14): error TS2461: Type 'null' is not an array type.
1+
tests/cases/conformance/es6/destructuring/restElementWithNullInitializer.ts(1,15): error TS2461: Type 'null' is not an array type.
2+
tests/cases/conformance/es6/destructuring/restElementWithNullInitializer.ts(4,15): error TS2461: Type 'undefined' is not an array type.
3+
tests/cases/conformance/es6/destructuring/restElementWithNullInitializer.ts(7,15): error TS2461: Type '{ [x: number]: undefined; }' is not an array type.
24

35

4-
==== tests/cases/conformance/es6/destructuring/restElementWithNullInitializer.ts (1 errors) ====
5-
function foo([...r] = null) { }
6-
~~~~~~
6+
==== tests/cases/conformance/es6/destructuring/restElementWithNullInitializer.ts (3 errors) ====
7+
function foo1([...r] = null) {
8+
~~~~~~
79
!!! error TS2461: Type 'null' is not an array type.
10+
}
11+
12+
function foo2([...r] = undefined) {
13+
~~~~~~
14+
!!! error TS2461: Type 'undefined' is not an array type.
15+
}
16+
17+
function foo3([...r] = {}) {
18+
~~~~~~
19+
!!! error TS2461: Type '{ [x: number]: undefined; }' is not an array type.
20+
}
21+
22+
function foo4([...r] = []) {
23+
}
824

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,27 @@
11
//// [restElementWithNullInitializer.ts]
2-
function foo([...r] = null) { }
2+
function foo1([...r] = null) {
3+
}
4+
5+
function foo2([...r] = undefined) {
6+
}
7+
8+
function foo3([...r] = {}) {
9+
}
10+
11+
function foo4([...r] = []) {
12+
}
313

414

515
//// [restElementWithNullInitializer.js]
6-
function foo(_a) { }
16+
function foo1(_a) {
17+
var _b = _a === void 0 ? null : _a, r = _b.slice(0);
18+
}
19+
function foo2(_a) {
20+
var _b = _a === void 0 ? undefined : _a, r = _b.slice(0);
21+
}
22+
function foo3(_a) {
23+
var _b = _a === void 0 ? {} : _a, r = _b.slice(0);
24+
}
25+
function foo4(_a) {
26+
var _b = _a === void 0 ? [] : _a, r = _b.slice(0);
27+
}
Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,11 @@
1-
function foo([...r] = null) { }
1+
function foo1([...r] = null) {
2+
}
3+
4+
function foo2([...r] = undefined) {
5+
}
6+
7+
function foo3([...r] = {}) {
8+
}
9+
10+
function foo4([...r] = []) {
11+
}

0 commit comments

Comments
 (0)