Fixed a false positive related to binding patterns and spread expressions

This commit is contained in:
Mateusz Burzyński
2022-06-26 16:22:05 +02:00
parent ad6d08675c
commit 1c43baa6eb
4 changed files with 44 additions and 1 deletions
+2 -1
View File
@@ -27970,7 +27970,8 @@ namespace ts {
// type with those properties for which the binding pattern specifies a default value.
// If the object literal is spread into another object literal, skip this step and let the top-level object
// literal handle it instead.
if (contextualTypeHasPattern && node.parent.kind !== SyntaxKind.SpreadAssignment) {
const spreadOrOutsidePossibleObjectParent = findAncestor(node, n => n.kind === SyntaxKind.SpreadAssignment || isStatement(n) || isArrowFunction(n))!;
if (contextualTypeHasPattern && spreadOrOutsidePossibleObjectParent.kind !== SyntaxKind.SpreadAssignment) {
for (const prop of getPropertiesOfType(contextualType)) {
if (!propertiesTable.get(prop.escapedName) && !getPropertyOfType(spread, prop.escapedName)) {
if (!(prop.flags & SymbolFlags.Optional)) {
@@ -0,0 +1,11 @@
=== tests/cases/compiler/spreadExpressionWithinIIFEReturnAssignedtoPattern.ts ===
// repro #49585
const { value } = (() => ({
>value : Symbol(value, Decl(spreadExpressionWithinIIFEReturnAssignedtoPattern.ts, 2, 7))
value: "",
>value : Symbol(value, Decl(spreadExpressionWithinIIFEReturnAssignedtoPattern.ts, 2, 27))
...(true ? {} : {}),
}))();
@@ -0,0 +1,23 @@
=== tests/cases/compiler/spreadExpressionWithinIIFEReturnAssignedtoPattern.ts ===
// repro #49585
const { value } = (() => ({
>value : string
>(() => ({ value: "", ...(true ? {} : {}),}))() : { value: string; }
>(() => ({ value: "", ...(true ? {} : {}),})) : () => { value: string; }
>() => ({ value: "", ...(true ? {} : {}),}) : () => { value: string; }
>({ value: "", ...(true ? {} : {}),}) : { value: string; }
>{ value: "", ...(true ? {} : {}),} : { value: string; }
value: "",
>value : string
>"" : ""
...(true ? {} : {}),
>(true ? {} : {}) : {}
>true ? {} : {} : {}
>true : true
>{} : {}
>{} : {}
}))();
@@ -0,0 +1,8 @@
// @noEmit: true
// repro #49585
const { value } = (() => ({
value: "",
...(true ? {} : {}),
}))();