-
Notifications
You must be signed in to change notification settings - Fork 12.9k
Closed
Labels
BugA bug in TypeScriptA bug in TypeScriptDesign LimitationConstraints of the existing architecture prevent this from being fixedConstraints of the existing architecture prevent this from being fixed
Milestone
Description
Bug Report
π Search Terms
TS2783, spread operator, control flow analysis
π Version & Regression Information
This changed between versions 4.3.5 and 4.4.4
β― Playground Link
Playground link with relevant code (thanks webstrand#8856 on the TS community server)
π» Code
const override = { color: "green" };
const conditional = false as boolean;
const example = {
color: "red", // TS2783 here
...(conditional ? override : { size: "large"})
}
const more = conditional ? override : { size: "large"};
const example2 = {
color: "red", // no TS2783 here
...more
}
π Actual behavior
When using a ternary expression within a spread operator to conditionally apply properties to an object, a TS2783 error (This spread always overwrites this property
) is raised even if the property is only overwritten in one branch of the conditional. The error is not present if the result of the ternary is assigned to a variable which is then applied with the spread operator.
π Expected behavior
TS2783 should not be raised in situations where the property is only conditionally overwritten by a spread.
jamesmeneghello, tadhgmister, gkiely and timothyaveni
Metadata
Metadata
Assignees
Labels
BugA bug in TypeScriptA bug in TypeScriptDesign LimitationConstraints of the existing architecture prevent this from being fixedConstraints of the existing architecture prevent this from being fixed