Skip to content
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

Add rule to detect completely useless object spread #398

Open
ajafff opened this issue Aug 31, 2018 · 0 comments
Open

Add rule to detect completely useless object spread #398

ajafff opened this issue Aug 31, 2018 · 0 comments
Assignees

Comments

@ajafff
Copy link
Member

ajafff commented Aug 31, 2018

Since microsoft/TypeScript#26798 there are no longer excess property errors for object spread. That also means you can spread anything, even if it doesn't have any property in common with the contextual type.

declare let foo: {a: string, b: string};

let bar: {c: string} = {...foo, c: ''}; // spreading `...foo` doesn't contribute any useful properties to `bar`
let foobar: {a: string, c: string} = {...foo, c: ''}; // this is valid because there is at least one overlapping property
let baz = {...foo, c: ''}; // this is valid because there is no contextual type
let bas: Record<string, string> = {...foo, c: ''}; // this is valid because of the index signature

I have no strong opinion whether this should be a new rule or integrated into an existing rule.
For a reference implementation regarding object spread, see no-duplicate-spread-property

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant