-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Erroneous TS2783 when ternary expressions are inlined in a spread operator #46463
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Broken by #44696, where I commented "I think it's fine to ship a stricter check; we'll see if people complain in the beta." I'm not sure the break was intentional, though, so I'm going to make sure. |
The new 4.4 code assumes that However, the type is still |
There are 3 ways to fix this, but none of them are satisfactory.
I don't think there's a good fix to this bug. The first two fixes are far-reaching, and have bad effects. The third fix still isn't really correct, especially when |
Fixes #46463, but I don't thik it's a good fix. See #46463 (comment) for discussion.
I pushed the fix to make-spread-overwrite-error-more-lenient for future reference. |
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
π 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.
The text was updated successfully, but these errors were encountered: