Skip to content

Spreading a get accessor property results in false positive "overwritten" error #47961

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
Dionysusnu opened this issue Feb 18, 2022 · 4 comments
Labels
Duplicate An existing issue was already created

Comments

@Dionysusnu
Copy link

Bug Report

πŸ”Ž Search Terms

spread, get, accessor, class

πŸ•— Version & Regression Information

  • This changed between versions 3.8.3 and 3.9.7

⏯ Playground Link

Playground link with relevant code

πŸ’» Code

class A {
    get bar() {
        return "Overwritten by getter";
    }
}

const foo = new A()
const a = {
    // False-positive error because `bar` will not be overwritten by a get accessor
    bar: "Was not overwritten",
    ...foo,
}
// `bar` is correctly not in `b`'s type, because it's from a get accessor
const b = {
    ...foo,
}

// logs `{"bar": "Was not overwritten"}`
console.log(a)
// logs `{}`
console.log(b)

πŸ™ Actual behavior

An error is thrown on line 10, reporting that bar is overwritten. However, get accessors do not overwrite properties during spread behaviour.

πŸ™‚ Expected behavior

The error should not be reported, because bar is not actually overwritten. This is already recognised, as the type of b shows the bar property is excluded when not specified in the literal.

@RyanCavanaugh RyanCavanaugh added the Duplicate An existing issue was already created label Feb 23, 2022
@RyanCavanaugh
Copy link
Member

See #9726 - enumerability is not tracked

@typescript-bot
Copy link
Collaborator

This issue has been marked as a 'Duplicate' and has seen no recent activity. It has been automatically closed for house-keeping purposes.

@Dionysusnu
Copy link
Author

It's kind of a separate bug though, isn't it? The type of b shows clearly that the enumerability is tracked in some way. It seems odd that that would then not be used for the overwriting diagnostic.

@Dionysusnu
Copy link
Author

For example, 47078 also added similar checks related to spreads.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Duplicate An existing issue was already created
Projects
None yet
Development

No branches or pull requests

3 participants