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 on static class members named 'constructor' should be consistent #33198

Open
ark120202 opened this issue Sep 2, 2019 · 2 comments
Open
Labels
Awaiting More Feedback This means we'd like to hear from more people who would be helped by this feature In Discussion Not yet reached consensus Suggestion An idea for TypeScript

Comments

@ark120202
Copy link

TypeScript Version: 3.7.0-dev.20190831

Search Terms: class, constructor, static, computed, quoted

Code

class A { static constructor() {} }
class B { static "constructor"() {} }
class C { static ["constructor"]() {} }

Expected behavior:

Even though it may be confused with non-standard extensions like #265, I think treating all cases equally would be less confusing, because unlike non-static ["constructor"] there is no difference at runtime.

Actual behavior:

A and B (with #31949) get a 'static' modifier cannot appear on a constructor declaration. diagnostic.

Playground Link:
http://www.typescriptlang.org/play/#code/MYGwhgzhAECC0G9oQC5hQS2NYB7AdqgE4CuwKuRAFAJSIC+09AUKJDAEKLJqbYBEeQilLlK-WgyatwUaAGFuqdFmgBtQQWJkKRfgF1JCRiyA

Related Issues: #31020, eslint/eslint#12110

@sandersn
Copy link
Member

sandersn commented Sep 3, 2019

I don't understand your expected behaviour here. Do you expect an error on all 3 or no errors at all?

As far as I understand, none of these 3 examples declares an actual constructor. Am I correct on that?

@sandersn sandersn added Needs More Info The issue still hasn't been fully clarified Suggestion An idea for TypeScript labels Sep 3, 2019
@ark120202
Copy link
Author

I don't understand your expected behaviour here. Do you expect an error on all 3 or no errors at all?

I think anything consistent would be fine. I personally prefer no errors, since, even if it's a bit confusing, all 3 cases are valid JS and disallowing confusing code better fits linter.

As far as I understand, none of these 3 examples declares an actual constructor. Am I correct on that?

Yes, all these 3 cases are equivalent to Class.constructor = function() {}.

@sandersn sandersn changed the title Static class members named 'constructor' Error on static class members named 'constructor' should be consistent Sep 4, 2019
@sandersn sandersn added Awaiting More Feedback This means we'd like to hear from more people who would be helped by this feature In Discussion Not yet reached consensus and removed Needs More Info The issue still hasn't been fully clarified labels Sep 4, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Awaiting More Feedback This means we'd like to hear from more people who would be helped by this feature In Discussion Not yet reached consensus Suggestion An idea for TypeScript
Projects
None yet
Development

No branches or pull requests

2 participants