mirror of
https://github.com/microsoft/TypeScript.git
synced 2025-11-18 17:21:48 +00:00
Fixed a false positive related to binding patterns and spread expressions
This commit is contained in:
@@ -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 ? {} : {}),
|
||||
}))();
|
||||
Reference in New Issue
Block a user