Skip to content

Commit 34f7f2c

Browse files
committed
Handle the scenario when let [a=undefined]=[]
1 parent 90d347e commit 34f7f2c

File tree

4 files changed

+15
-9
lines changed

4 files changed

+15
-9
lines changed

src/compiler/checker.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2885,11 +2885,7 @@ namespace ts {
28852885
// pattern. Otherwise, it is the type any.
28862886
function getTypeFromBindingElement(element: BindingElement, includePatternInType?: boolean, reportErrors?: boolean): Type {
28872887
if (element.initializer) {
2888-
const type = checkExpressionCached(element.initializer);
2889-
if (reportErrors) {
2890-
reportErrorsFromWidening(element, type);
2891-
}
2892-
return getWidenedType(type);
2888+
return checkExpressionCached(element.initializer);
28932889
}
28942890
if (isBindingPattern(element.name)) {
28952891
return getTypeFromBindingPattern(<BindingPattern>element.name, includePatternInType, reportErrors);

tests/baselines/reference/noImplicitAnyDestructuringVarDeclaration.errors.txt

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,10 @@ tests/cases/compiler/noImplicitAnyDestructuringVarDeclaration.ts(9,6): error TS7
1919
tests/cases/compiler/noImplicitAnyDestructuringVarDeclaration.ts(9,26): error TS7031: Binding element 'b4' implicitly has an 'any' type.
2020
tests/cases/compiler/noImplicitAnyDestructuringVarDeclaration.ts(9,46): error TS7005: Variable 'c4' implicitly has an 'any' type.
2121
tests/cases/compiler/noImplicitAnyDestructuringVarDeclaration.ts(9,62): error TS7005: Variable 'd4' implicitly has an 'any' type.
22+
tests/cases/compiler/noImplicitAnyDestructuringVarDeclaration.ts(11,6): error TS7031: Binding element 'a5' implicitly has an 'any' type.
2223

2324

24-
==== tests/cases/compiler/noImplicitAnyDestructuringVarDeclaration.ts (21 errors) ====
25+
==== tests/cases/compiler/noImplicitAnyDestructuringVarDeclaration.ts (22 errors) ====
2526
var [a], {b}, c, d; // error
2627
~~~
2728
!!! error TS1182: A destructuring declaration must have an initializer.
@@ -72,4 +73,8 @@ tests/cases/compiler/noImplicitAnyDestructuringVarDeclaration.ts(9,62): error TS
7273
~~
7374
!!! error TS7005: Variable 'c4' implicitly has an 'any' type.
7475
~~
75-
!!! error TS7005: Variable 'd4' implicitly has an 'any' type.
76+
!!! error TS7005: Variable 'd4' implicitly has an 'any' type.
77+
78+
var [a5 = undefined] = []; // error
79+
~~
80+
!!! error TS7031: Binding element 'a5' implicitly has an 'any' type.

tests/baselines/reference/noImplicitAnyDestructuringVarDeclaration.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,14 @@ var [a2]: [any], {b2}: { b2: any }, c2: any, d2: any;
77

88
var {b3}: { b3 }, c3: { b3 }; // error in type instead
99

10-
var [a4] = [undefined], {b4} = { b4: null }, c4 = undefined, d4 = null; // error
10+
var [a4] = [undefined], {b4} = { b4: null }, c4 = undefined, d4 = null; // error
11+
12+
var [a5 = undefined] = []; // error
1113

1214
//// [noImplicitAnyDestructuringVarDeclaration.js]
1315
var a = (void 0)[0], b = (void 0).b, c, d; // error
1416
var _a = (void 0)[0], a1 = _a === void 0 ? undefined : _a, _b = (void 0).b1, b1 = _b === void 0 ? null : _b, c1 = undefined, d1 = null; // error
1517
var a2 = (void 0)[0], b2 = (void 0).b2, c2, d2;
1618
var b3 = (void 0).b3, c3; // error in type instead
1719
var a4 = [undefined][0], b4 = { b4: null }.b4, c4 = undefined, d4 = null; // error
20+
var _c = [][0], a5 = _c === void 0 ? undefined : _c; // error

tests/cases/compiler/noImplicitAnyDestructuringVarDeclaration.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,6 @@ var [a2]: [any], {b2}: { b2: any }, c2: any, d2: any;
77

88
var {b3}: { b3 }, c3: { b3 }; // error in type instead
99

10-
var [a4] = [undefined], {b4} = { b4: null }, c4 = undefined, d4 = null; // error
10+
var [a4] = [undefined], {b4} = { b4: null }, c4 = undefined, d4 = null; // error
11+
12+
var [a5 = undefined] = []; // error

0 commit comments

Comments
 (0)