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

Error: Property is overwritten by later spread #27645

Closed
wants to merge 4 commits into from

Conversation

sandersn
Copy link
Member

@sandersn sandersn commented Oct 9, 2018

Move the checking from JSX to getSpreadType so that normal objects get the error too.

Also reword the missing semicolon related error to be less silly.

Fixes #27355 (probably)

Move the checking from JSX to getSpreadType so that normal objects get
the error too.

Also reword the missing semicolon related error to be less silly.
@sandersn
Copy link
Member Author

sandersn commented Oct 9, 2018

Note that the related span didn't work out because getSpreadType doesn't have easy access to the usage of properties, just their declarations. For spread properties, the declaration is a really bad site for a related span. I decided that the additional complexity of determining the usage site wasn't worth it.

@sandersn sandersn requested review from weswigham and a user October 9, 2018 22:15
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
!!! error TS2710: 'children' are specified twice. The attribute named 'children' will be overwritten.
~~~~~~~~~~~~~~~~~
!!! error TS2735: 'children' is overwritten by a later spread.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Error message is inaccurate here

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
!!! error TS2710: 'children' are specified twice. The attribute named 'children' will be overwritten.
~~~~~~~~~~~~~
!!! error TS2735: 'children' is overwritten by a later spread.
Copy link
Member

@weswigham weswigham Oct 9, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

..."later spread"? Methinks this needs a different error message, since it's not being overridden by a spread, but by the actual children tags in the AST.

tests/cases/conformance/types/spread/objectSpreadNegative.ts(58,11): error TS2339: Property 'a' does not exist on type '{}'.
tests/cases/conformance/types/spread/objectSpreadNegative.ts(62,14): error TS2698: Spread types may only be created from object types.
tests/cases/conformance/types/spread/objectSpreadNegative.ts(65,14): error TS2698: Spread types may only be created from object types.
tests/cases/conformance/types/spread/objectSpreadNegative.ts(27,20): error TS2735: 'b' is overwritten by a later spread.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think it's safe to emit this error outside of strictNullChecks in normal circumstances (JSX children being one of the few where it is).

@weswigham
Copy link
Member

For spread properties, the declaration is a really bad site for a related span. I decided that the additional complexity of determining the usage site wasn't worth it.

We should have a related span that calls out which following spread (just in case there are multiple) is the one which overrides the property.

@ghost
Copy link

ghost commented Oct 9, 2018

False positive:

function f(obj: { x: number } | undefined): { x: number } {
    return { x: 1, ...obj };
}

(mentioned by @ajafff in #23340)

@sandersn
Copy link
Member Author

@andy-ms Actually, the related example that you gave in that issue also fails, with obj: { x: number | undefined }. I have a commit that fixes these two problems, but it does so by not issuing the error for any union-distributed spread (fixes the first example) and not issuing the error for any nullable-containing property type (fixes the second example). It also reverts the JsX test changes, although that issue isn’t really fixed.

Basically, this fix is more complicated than I hoped, so I’m going to put it on hold until I address more urgent 3.2work.

Doesn't fix JSX problems
@matthargett
Copy link

3.2 has been out for a while -- any updates on this fix, or one that supersedes it? :D if there were complications, can they be described in a comment so we can understand better?

@sandersn
Copy link
Member Author

#36727 is the revived version of this, which is now merged.

@sandersn sandersn closed this Feb 12, 2020
@jakebailey jakebailey deleted the error-property-overwritten-by-later-spread branch November 7, 2022 17:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Author: Team For Milestone Bug PRs that fix a bug with a specific milestone
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Missing excess property error with spread
6 participants