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

Incorrect error 2301 when using ES standard class properties #49719

Open
sandersn opened this issue Jun 29, 2022 · 1 comment · May be fixed by #49725
Open

Incorrect error 2301 when using ES standard class properties #49719

sandersn opened this issue Jun 29, 2022 · 1 comment · May be fixed by #49725
Labels
Bug Good First Issue
Milestone

Comments

@sandersn
Copy link
Member

@sandersn sandersn commented Jun 29, 2022

As explained in #2548, the following code is not correct when useDefineForClassFields: false, the default for targets before ES2021, or when target <= ES2020.

const x = 1
class C {
    p = x
    constructor(x: string) { }
}

However, when useDefineForClassFields: true and target >= ES2021, there shouldn't be an error here.

Expected: No error 2301 on private p = x, and p: number
Actual: Error on private p = x and p: any

Edit: @fatcerberus pointed out that the error is only incorrect when useDefineForClassFields: true and target >= ES2021, because downlevel define for class fields still happens in the constructor.

@sandersn sandersn added Bug Good First Issue labels Jun 29, 2022
@sandersn sandersn added this to the Backlog milestone Jun 29, 2022
@fatcerberus
Copy link

@fatcerberus fatcerberus commented Jun 30, 2022

This is broken because the outer x gets shadowed by the ctor parameter, right? But that means it’s also broken for downleveled useDefineForClassFields too…

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

Successfully merging a pull request may close this issue.

2 participants