Skip to content

Conversation

@ajafff
Copy link
Member

@ajafff ajafff commented Apr 12, 2018

Checklist

Overview of change

Adds a rule to detect properties in object literals that are overridden later by a spreaded object.
It also detects spreaded objects that only contain properties that are overridden later.

TBD

  • is there a better name for the rule?
  • how to handle properties that are not optional, but may contain undefined? The compiler doesn't allow assigning optional properties to non-optional ones, but maybe some libraries typings are not correct.

@ajafff
Copy link
Member Author

ajafff commented Apr 26, 2018

Two things to note here:

  • a better name would be no-duplicate-spread-property
  • this rule will never work 100% correct. object spread only copies own properties. properties and methods on the prototype not copied although they part of the type (they cannot be distinguished from own properties)

@ajafff
Copy link
Member Author

ajafff commented Apr 26, 2018

Some more details on the design limitation regarding own properties vs. prototype properties: microsoft/TypeScript#13148 (comment)

TODO: only omit class methods, but include properties with call signatures. See microsoft/TypeScript#13365 for more details

@ajafff ajafff changed the title new rule: no-useless-object-property new rule: no-duplicate-spread-property Apr 26, 2018
@ajafff ajafff merged commit 4e5183b into master Apr 26, 2018
@ajafff ajafff deleted the no-useless-object-property branch April 26, 2018 20:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants