Addressing CR feedback

This commit is contained in:
Anders Hejlsberg 2015-02-21 19:33:53 -08:00
parent 95b3d6be58
commit ca92653aba
4 changed files with 56 additions and 8 deletions

View file

@ -1721,7 +1721,7 @@ module ts {
}
}
else {
// For an array binding element the specified or inferred type of the parent must be assignable to any[]
// For an array binding element the specified or inferred type of the parent must be an array-like type
if (!isArrayLikeType(parentType)) {
error(pattern, Diagnostics.Type_0_is_not_an_array_type, typeToString(parentType));
return unknownType;
@ -4191,6 +4191,7 @@ module ts {
}
function isArrayLikeType(type: Type): boolean {
// A type is array-like if it is not the undefined or null type and if it is assignable to any[]
return !(type.flags & (TypeFlags.Undefined | TypeFlags.Null)) && isTypeAssignableTo(type, anyArrayType);
}

View file

@ -1,8 +1,24 @@
tests/cases/conformance/es6/destructuring/restElementWithNullInitializer.ts(1,14): error TS2461: Type 'null' is not an array type.
tests/cases/conformance/es6/destructuring/restElementWithNullInitializer.ts(1,15): error TS2461: Type 'null' is not an array type.
tests/cases/conformance/es6/destructuring/restElementWithNullInitializer.ts(4,15): error TS2461: Type 'undefined' is not an array type.
tests/cases/conformance/es6/destructuring/restElementWithNullInitializer.ts(7,15): error TS2461: Type '{ [x: number]: undefined; }' is not an array type.
==== tests/cases/conformance/es6/destructuring/restElementWithNullInitializer.ts (1 errors) ====
function foo([...r] = null) { }
~~~~~~
==== tests/cases/conformance/es6/destructuring/restElementWithNullInitializer.ts (3 errors) ====
function foo1([...r] = null) {
~~~~~~
!!! error TS2461: Type 'null' is not an array type.
}
function foo2([...r] = undefined) {
~~~~~~
!!! error TS2461: Type 'undefined' is not an array type.
}
function foo3([...r] = {}) {
~~~~~~
!!! error TS2461: Type '{ [x: number]: undefined; }' is not an array type.
}
function foo4([...r] = []) {
}

View file

@ -1,6 +1,27 @@
//// [restElementWithNullInitializer.ts]
function foo([...r] = null) { }
function foo1([...r] = null) {
}
function foo2([...r] = undefined) {
}
function foo3([...r] = {}) {
}
function foo4([...r] = []) {
}
//// [restElementWithNullInitializer.js]
function foo(_a) { }
function foo1(_a) {
var _b = _a === void 0 ? null : _a, r = _b.slice(0);
}
function foo2(_a) {
var _b = _a === void 0 ? undefined : _a, r = _b.slice(0);
}
function foo3(_a) {
var _b = _a === void 0 ? {} : _a, r = _b.slice(0);
}
function foo4(_a) {
var _b = _a === void 0 ? [] : _a, r = _b.slice(0);
}

View file

@ -1 +1,11 @@
function foo([...r] = null) { }
function foo1([...r] = null) {
}
function foo2([...r] = undefined) {
}
function foo3([...r] = {}) {
}
function foo4([...r] = []) {
}