Skip to content

constructor can't be the name of class accessors and generators. #48948

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
g-plane opened this issue May 4, 2022 · 1 comment · Fixed by #48954
Closed

constructor can't be the name of class accessors and generators. #48948

g-plane opened this issue May 4, 2022 · 1 comment · Fixed by #48954
Labels
Bug A bug in TypeScript Fixed A PR has been merged for this issue Good First Issue Well scoped, documented and has the green light Help Wanted You can do this

Comments

@g-plane
Copy link
Contributor

g-plane commented May 4, 2022

Bug Report

In classes, accessors (aka getters/setters) and generators can't be named with constructor. They're Syntax Errors defined in spec.

References:

🔎 Search Terms

constructor
getter
setter
accessor
generator

🕗 Version & Regression Information

Tested on 4.5.5, 4.6.2 and Nightly (4.7).

⏯ Playground Link

Playground link with relevant code

💻 Code

class C1 {
    get constructor() {
        return
    }
    set constructor(value) {}
}

class C2 {
    *constructor() {}
}

🙁 Actual behavior

No errors reported.

🙂 Expected behavior

TypeScript should report errors for misusing constructor as accessor name for Line 2 and Line 5, and report error for misusing constructor as generator for Line 9 in the example above.

@andrewbranch andrewbranch added Bug A bug in TypeScript Help Wanted You can do this Good First Issue Well scoped, documented and has the green light labels May 4, 2022
@andrewbranch andrewbranch added this to the Backlog milestone May 4, 2022
@DanielRosenwasser DanielRosenwasser added the Fixed A PR has been merged for this issue label May 13, 2022
@DanielRosenwasser
Copy link
Member

Thanks @a-tarasyuk!

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 Good First Issue Well scoped, documented and has the green light Help Wanted You can do this
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants