Skip to content

Commit a82d1f8

Browse files
Kingwlmhegazy
authored andcommitted
ignore Initial check if left of DestructuringAsignment (microsoft#20906)
1 parent 06c9a28 commit a82d1f8

5 files changed

Lines changed: 40 additions & 1 deletion

src/compiler/checker.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13333,6 +13333,7 @@ namespace ts {
1333313333
const declarationContainer = getControlFlowContainer(declaration);
1333413334
let flowContainer = getControlFlowContainer(node);
1333513335
const isOuterVariable = flowContainer !== declarationContainer;
13336+
const isSpreadDestructuringAsignmentTarget = node.parent && node.parent.parent && isSpreadAssignment(node.parent) && isDestructuringAssignmentTarget(node.parent.parent);
1333613337
// When the control flow originates in a function expression or arrow function and we are referencing
1333713338
// a const variable or parameter from an outer function, we extend the origin of the control flow
1333813339
// analysis to include the immediately enclosing function.
@@ -13344,7 +13345,7 @@ namespace ts {
1334413345
// We only look for uninitialized variables in strict null checking mode, and only when we can analyze
1334513346
// the entire control flow graph from the variable's declaration (i.e. when the flow container and
1334613347
// declaration container are the same).
13347-
const assumeInitialized = isParameter || isAlias || isOuterVariable ||
13348+
const assumeInitialized = isParameter || isAlias || isOuterVariable || isSpreadDestructuringAsignmentTarget ||
1334813349
type !== autoType && type !== autoArrayType && (!strictNullChecks || (type.flags & TypeFlags.Any) !== 0 ||
1334913350
isInTypeQuery(node) || node.parent.kind === SyntaxKind.ExportSpecifier) ||
1335013351
node.parent.kind === SyntaxKind.NonNullExpression ||
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
//// [destructuringAssignmentWithStrictNullChecks.ts]
2+
let bar: {};
3+
({ ...bar } = {});
4+
5+
6+
//// [destructuringAssignmentWithStrictNullChecks.js]
7+
var __rest = (this && this.__rest) || function (s, e) {
8+
var t = {};
9+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
10+
t[p] = s[p];
11+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
12+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) if (e.indexOf(p[i]) < 0)
13+
t[p[i]] = s[p[i]];
14+
return t;
15+
};
16+
var bar;
17+
(bar = __rest({}, []));
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
=== tests/cases/compiler/destructuringAssignmentWithStrictNullChecks.ts ===
2+
let bar: {};
3+
>bar : Symbol(bar, Decl(destructuringAssignmentWithStrictNullChecks.ts, 0, 3))
4+
5+
({ ...bar } = {});
6+
>bar : Symbol(bar, Decl(destructuringAssignmentWithStrictNullChecks.ts, 0, 3))
7+
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
=== tests/cases/compiler/destructuringAssignmentWithStrictNullChecks.ts ===
2+
let bar: {};
3+
>bar : {}
4+
5+
({ ...bar } = {});
6+
>({ ...bar } = {}) : {}
7+
>{ ...bar } = {} : {}
8+
>{ ...bar } : {}
9+
>bar : {}
10+
>{} : {}
11+
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
// @strictNullChecks: true
2+
let bar: {};
3+
({ ...bar } = {});

0 commit comments

Comments
 (0)