-
Notifications
You must be signed in to change notification settings - Fork 12.6k
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
Allow defining static index signature #6480
Comments
Figured that I can access the value of a static property using the following notation. Is that error expected though? Is that because console.log((<any>Foo)['B' + 'A' + 'Z']);
console.log((<any>Foo)['qux']); |
You're correct -- the declared index signature only applies to the instance side of the class, not the constructor function itself. Presumably we'd allow you to fix this without a type assertion by writing |
Frankly |
It makes sense from purely a code perspective... but what are you doing, exactly? When designing this feature we basically said "Do we ever need |
I have a class which acts like enum and holds a bunch of constants. Though there are string enums, this is more appropriate & convenient for my case. And I need to check if the constant is there or not, which doesn't work nicely with |
Accepting PRs. This should be a fairly easy change for someone familiar with the compiler, just checking for some flags during type construction. |
Has there been any progress on this in the past year? I'm running into this in a project, and it's blocking me, but I am not "familiar with the compiler", so I cannot make the fix myself. |
@RyanCavanaugh Obviously need this feature. My usecase: let method = isMethodStatic ? ExtendedClass[methodName] : new ExtendedClass(someData)[methodName] Writing |
Accepting PRs means that the core team do not have the time to address this and it is open to the community to solve. |
friendly ping @ianbytchek @nikis05 @markspolakovs I have a pr for this one. |
same problem. |
Thanks @Kingwl! |
I get the following errors with this:
I've read in the gitter archives that this should be working. Should it? How can I get a static property value using a dynamic key?
The text was updated successfully, but these errors were encountered: