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

Do not allow to define a static name property on classes #3190

Closed
lazdmx opened this issue May 17, 2015 · 2 comments
Closed

Do not allow to define a static name property on classes #3190

lazdmx opened this issue May 17, 2015 · 2 comments
Labels
Duplicate An existing issue was already created

Comments

@lazdmx
Copy link

lazdmx commented May 17, 2015

Currently it is possible to redefine a static name property for classes which leads to some unclear results in runtime - it returns class name at runtime.

class A {
    static name = 'Some name'

    static getName() {
        return this.name
    }
}


alert(A.getName()) // Shows `A` instead of `Some name`

So I think that there are two problems.

  1. A type-system couldn't find a name as apparent member derived from Function type and as it follows removing a line static name = 'Some name' leads to compilation error.
  2. I suggest that TS should notify when I try to redefine a name by issuing error or warning (if they are) because a good-looking code would works incorrectly in runtime.
@tinganho
Copy link
Contributor

Look at #442. I think it is impossible for TS to implement a static name property on classes.

@lazdmx
Copy link
Author

lazdmx commented May 17, 2015

Thanks, didn't know. I will continue discussion in that issue.

@lazdmx lazdmx closed this as completed May 17, 2015
@mhegazy mhegazy added the Duplicate An existing issue was already created label May 18, 2015
@microsoft microsoft locked and limited conversation to collaborators Jun 19, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Duplicate An existing issue was already created
Projects
None yet
Development

No branches or pull requests

3 participants