mirror of
https://github.com/microsoft/TypeScript.git
synced 2025-11-18 17:21:48 +00:00
Merge pull request #8387 from Microsoft/controlFlowDestructuringParameter
Fix control flow analysis for destructuring parameters
This commit is contained in:
@@ -7959,7 +7959,7 @@ namespace ts {
|
||||
}
|
||||
const declaration = localOrExportSymbol.valueDeclaration;
|
||||
const defaultsToDeclaredType = !strictNullChecks || type.flags & TypeFlags.Any || !declaration ||
|
||||
declaration.kind === SyntaxKind.Parameter || isInAmbientContext(declaration) ||
|
||||
getRootDeclaration(declaration).kind === SyntaxKind.Parameter || isInAmbientContext(declaration) ||
|
||||
getContainingFunctionOrModule(declaration) !== getContainingFunctionOrModule(node);
|
||||
const flowType = getFlowTypeOfReference(node, type, defaultsToDeclaredType ? type : undefinedType);
|
||||
if (strictNullChecks && !(type.flags & TypeFlags.Any) && !(getNullableKind(type) & TypeFlags.Undefined) && getNullableKind(flowType) & TypeFlags.Undefined) {
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
//// [controlFlowDestructuringParameters.ts]
|
||||
// Repro for #8376
|
||||
|
||||
|
||||
[{ x: 1 }].map(
|
||||
({ x }) => x
|
||||
);
|
||||
|
||||
|
||||
//// [controlFlowDestructuringParameters.js]
|
||||
// Repro for #8376
|
||||
[{ x: 1 }].map(function (_a) {
|
||||
var x = _a.x;
|
||||
return x;
|
||||
});
|
||||
@@ -0,0 +1,15 @@
|
||||
=== tests/cases/compiler/controlFlowDestructuringParameters.ts ===
|
||||
// Repro for #8376
|
||||
|
||||
|
||||
[{ x: 1 }].map(
|
||||
>[{ x: 1 }].map : Symbol(Array.map, Decl(lib.d.ts, --, --))
|
||||
>x : Symbol(x, Decl(controlFlowDestructuringParameters.ts, 3, 2))
|
||||
>map : Symbol(Array.map, Decl(lib.d.ts, --, --))
|
||||
|
||||
({ x }) => x
|
||||
>x : Symbol(x, Decl(controlFlowDestructuringParameters.ts, 4, 4))
|
||||
>x : Symbol(x, Decl(controlFlowDestructuringParameters.ts, 4, 4))
|
||||
|
||||
);
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
=== tests/cases/compiler/controlFlowDestructuringParameters.ts ===
|
||||
// Repro for #8376
|
||||
|
||||
|
||||
[{ x: 1 }].map(
|
||||
>[{ x: 1 }].map( ({ x }) => x) : number[]
|
||||
>[{ x: 1 }].map : <U>(callbackfn: (value: { x: number; }, index: number, array: { x: number; }[]) => U, thisArg?: any) => U[]
|
||||
>[{ x: 1 }] : { x: number; }[]
|
||||
>{ x: 1 } : { x: number; }
|
||||
>x : number
|
||||
>1 : number
|
||||
>map : <U>(callbackfn: (value: { x: number; }, index: number, array: { x: number; }[]) => U, thisArg?: any) => U[]
|
||||
|
||||
({ x }) => x
|
||||
>({ x }) => x : ({x}: { x: number; }) => number
|
||||
>x : number
|
||||
>x : number
|
||||
|
||||
);
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
// Repro for #8376
|
||||
|
||||
// @strictNullChecks: true
|
||||
|
||||
[{ x: 1 }].map(
|
||||
({ x }) => x
|
||||
);
|
||||
Reference in New Issue
Block a user