Skip to content

Missing excess property error with spread #27355

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

Closed
ghost opened this issue Sep 26, 2018 · 3 comments · Fixed by #36727
Closed

Missing excess property error with spread #27355

ghost opened this issue Sep 26, 2018 · 3 comments · Fixed by #36727
Assignees
Labels
Bug A bug in TypeScript Fixed A PR has been merged for this issue

Comments

@ghost
Copy link

ghost commented Sep 26, 2018

TypeScript Version: 3.1.0-dev.201xxxxx

Code

function f(o: { a: number, b: number }): { a: number } {
    return { b: 0, ...o };
}

Expected behavior:

Error on b.

Actual behavior:

No error.

Broken by #26798.

Related Issues: #27166, #23340

@ghost ghost assigned sandersn Sep 26, 2018
@ghost ghost added the Bug A bug in TypeScript label Sep 26, 2018
@sandersn sandersn added this to the TypeScript 3.2 milestone Oct 8, 2018
@sandersn
Copy link
Member

sandersn commented Oct 9, 2018

@weswigham points out that this is probably correct; b: 0 is not excess because it's overridden by o.b which comes from a spread, so should not count as excess.

What would be more useful is an error for unused properties in a spread: any property that is not used because of later spreads. The error should only apply to non-spread properties.

@WreckedArrow
Copy link

I'm not sure if this is related or has been addressed elsewhere, but this also does not produce an error:

function f(o: { a: number, b: number }): { a: number } {
    return o;
}

@ghost
Copy link
Author

ghost commented Oct 13, 2018

@WreckedArrow That's #12936

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug A bug in TypeScript Fixed A PR has been merged for this issue
Projects
None yet
4 participants