Addressing CR feedback
This commit is contained in:
parent
95b3d6be58
commit
ca92653aba
|
@ -1721,7 +1721,7 @@ module ts {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
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)) {
|
if (!isArrayLikeType(parentType)) {
|
||||||
error(pattern, Diagnostics.Type_0_is_not_an_array_type, typeToString(parentType));
|
error(pattern, Diagnostics.Type_0_is_not_an_array_type, typeToString(parentType));
|
||||||
return unknownType;
|
return unknownType;
|
||||||
|
@ -4191,6 +4191,7 @@ module ts {
|
||||||
}
|
}
|
||||||
|
|
||||||
function isArrayLikeType(type: Type): boolean {
|
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);
|
return !(type.flags & (TypeFlags.Undefined | TypeFlags.Null)) && isTypeAssignableTo(type, anyArrayType);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -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) ====
|
==== tests/cases/conformance/es6/destructuring/restElementWithNullInitializer.ts (3 errors) ====
|
||||||
function foo([...r] = null) { }
|
function foo1([...r] = null) {
|
||||||
~~~~~~
|
~~~~~~
|
||||||
!!! error TS2461: Type 'null' is not an array type.
|
!!! 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] = []) {
|
||||||
|
}
|
||||||
|
|
|
@ -1,6 +1,27 @@
|
||||||
//// [restElementWithNullInitializer.ts]
|
//// [restElementWithNullInitializer.ts]
|
||||||
function foo([...r] = null) { }
|
function foo1([...r] = null) {
|
||||||
|
}
|
||||||
|
|
||||||
|
function foo2([...r] = undefined) {
|
||||||
|
}
|
||||||
|
|
||||||
|
function foo3([...r] = {}) {
|
||||||
|
}
|
||||||
|
|
||||||
|
function foo4([...r] = []) {
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
//// [restElementWithNullInitializer.js]
|
//// [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);
|
||||||
|
}
|
||||||
|
|
|
@ -1 +1,11 @@
|
||||||
function foo([...r] = null) { }
|
function foo1([...r] = null) {
|
||||||
|
}
|
||||||
|
|
||||||
|
function foo2([...r] = undefined) {
|
||||||
|
}
|
||||||
|
|
||||||
|
function foo3([...r] = {}) {
|
||||||
|
}
|
||||||
|
|
||||||
|
function foo4([...r] = []) {
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue