Handle the scenario when let [a=undefined]=[]

This commit is contained in:
Sheetal Nandi
2016-04-22 10:40:06 -07:00
parent 90d347e855
commit 34f7f2caed
4 changed files with 15 additions and 9 deletions
+1 -5
View File
@@ -2885,11 +2885,7 @@ namespace ts {
// pattern. Otherwise, it is the type any.
function getTypeFromBindingElement(element: BindingElement, includePatternInType?: boolean, reportErrors?: boolean): Type {
if (element.initializer) {
const type = checkExpressionCached(element.initializer);
if (reportErrors) {
reportErrorsFromWidening(element, type);
}
return getWidenedType(type);
return checkExpressionCached(element.initializer);
}
if (isBindingPattern(element.name)) {
return getTypeFromBindingPattern(<BindingPattern>element.name, includePatternInType, reportErrors);
@@ -19,9 +19,10 @@ tests/cases/compiler/noImplicitAnyDestructuringVarDeclaration.ts(9,6): error TS7
tests/cases/compiler/noImplicitAnyDestructuringVarDeclaration.ts(9,26): error TS7031: Binding element 'b4' implicitly has an 'any' type.
tests/cases/compiler/noImplicitAnyDestructuringVarDeclaration.ts(9,46): error TS7005: Variable 'c4' implicitly has an 'any' type.
tests/cases/compiler/noImplicitAnyDestructuringVarDeclaration.ts(9,62): error TS7005: Variable 'd4' implicitly has an 'any' type.
tests/cases/compiler/noImplicitAnyDestructuringVarDeclaration.ts(11,6): error TS7031: Binding element 'a5' implicitly has an 'any' type.
==== tests/cases/compiler/noImplicitAnyDestructuringVarDeclaration.ts (21 errors) ====
==== tests/cases/compiler/noImplicitAnyDestructuringVarDeclaration.ts (22 errors) ====
var [a], {b}, c, d; // error
~~~
!!! error TS1182: A destructuring declaration must have an initializer.
@@ -72,4 +73,8 @@ tests/cases/compiler/noImplicitAnyDestructuringVarDeclaration.ts(9,62): error TS
~~
!!! error TS7005: Variable 'c4' implicitly has an 'any' type.
~~
!!! error TS7005: Variable 'd4' implicitly has an 'any' type.
!!! error TS7005: Variable 'd4' implicitly has an 'any' type.
var [a5 = undefined] = []; // error
~~
!!! error TS7031: Binding element 'a5' implicitly has an 'any' type.
@@ -7,7 +7,9 @@ var [a2]: [any], {b2}: { b2: any }, c2: any, d2: any;
var {b3}: { b3 }, c3: { b3 }; // error in type instead
var [a4] = [undefined], {b4} = { b4: null }, c4 = undefined, d4 = null; // error
var [a4] = [undefined], {b4} = { b4: null }, c4 = undefined, d4 = null; // error
var [a5 = undefined] = []; // error
//// [noImplicitAnyDestructuringVarDeclaration.js]
var a = (void 0)[0], b = (void 0).b, c, d; // error
@@ -15,3 +17,4 @@ var _a = (void 0)[0], a1 = _a === void 0 ? undefined : _a, _b = (void 0).b1, b1
var a2 = (void 0)[0], b2 = (void 0).b2, c2, d2;
var b3 = (void 0).b3, c3; // error in type instead
var a4 = [undefined][0], b4 = { b4: null }.b4, c4 = undefined, d4 = null; // error
var _c = [][0], a5 = _c === void 0 ? undefined : _c; // error
@@ -7,4 +7,6 @@ var [a2]: [any], {b2}: { b2: any }, c2: any, d2: any;
var {b3}: { b3 }, c3: { b3 }; // error in type instead
var [a4] = [undefined], {b4} = { b4: null }, c4 = undefined, d4 = null; // error
var [a4] = [undefined], {b4} = { b4: null }, c4 = undefined, d4 = null; // error
var [a5 = undefined] = []; // error