-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
{ [key in keyof typeof Enum]: any } is not index signature #20011
Comments
Should be fixed in TS 2.6 (playground link). |
wow that was fast ... nes time i will try update ts first 👍 |
updated to 2.6.1 and error still persist. This is my real code: enum State {
Fail, Inconclusive, Running, Success,
}
type StateKeys = keyof typeof State;
type States = {
[state in StateKeys]: string[]
};
const test: States = getStatesSomehow();
const state = State.Fail;
// Element implicitly has an 'any' type because type 'States' has no index signature.
test[state].push('something');
~~~~~~~~~~~ |
|
yea .... silly me :) ... btw: could be that error message tweaked little - basically print your response? |
if you want to take a stab at making the error better and send us a PR, would be happy to review it. |
How would one use this type of key, but then use the enum value instead? As in : enum Name {
Fred = "fred",
Vilma = "vilma"
}
...
test["fred"].push('something'); |
@chriszrc i would use it this way: test[Name.Fred].push('something'); |
TypeScript Version: 2.4.1
Code
Expected behavior:
No error
Actual behavior:
Compilation error message:
Element implicitly has an 'any' type because type '{ readonly Fred: Data; readonly Vilma: Data; ...' has no index signature.
can be fixed by casting data to
any
or to{ [name: string]: Data }
before using indexerThe text was updated successfully, but these errors were encountered: