-
Notifications
You must be signed in to change notification settings - Fork 12.6k
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
Warn on unused property in object literal with spread #23340
Comments
Since this will never result in an error at runtime, it should better be implemented by a linter. |
@andy-ms I actually liked the idea, so I implemented it as a lint rule. The rule also covers the case where all properties of a spreaded object are overridden later in the literal. On a related note: I also implemented a rule to enforce |
Seems like a good idea even though it's technically a breaking change. Accepting PRs, should be easy enough for anyone familiar with the code or maybe @ajafff wants to port over the lint logic? |
@sandersn Might have some implementation comments -- note that we are somehow detecting dead properties as the following compiles: const o: { x: number } = { x: "", ...{ x: 0 } }; @ajafff's solution at https://github.com/fimbullinter/wotan/pull/185/files#diff-99a6bc6475c02de7f607e3fe08ae7be0 is also pretty short. |
Couple of observations:
|
@sandersn But we only care about whether the properties are present, not whether they're undefined. |
Re: optionality with strictNullChecks disabled let x = 1;
({ x, ...Boolean() && {x} }); The type of the spreaded expression was |
You're right though, we should disable this in non-
|
This is fixed now |
TypeScript Version: 2.9.0-dev.20180411
Search Terms: object spread unused property
Code
Expected behavior:
Error at
{ x, ...p }
: The firstx
is dead because...p
has its own non-optionalx
.Actual behavior:
No error at
{ x, ...p }
.The text was updated successfully, but these errors were encountered: