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
Querying Enums containing string initializers with a variable throws TS7015 #17800
Comments
just remove the type annotation: const test = 'Red';
// alternative
const test: keyof Colors = 'Red'; |
Seems we never did anything different with the indexing rules for string enums, which is bad. |
I found the fix!
I had the same problem and that fixed it. |
I've a different repro case. Source:
Workaround: Expected behavior: Actual behavior:
|
Thanks, @fmpierce! Used your solution in the following: Object.keys(Colors).map((color: keyof typeof Color): JSX.Element => {
return (
<div
key={color}
onClick={() => this._methodThatTakesAnEnum(Color[color])}
>
{ Util.functionThatTakesAString(color) }
</div>
);
}); The anon function signature |
I don't really see this as a bug at this point - enums don't have index signatures, it'd be a huge break to add one now, and it doesn't seem to merit a special case in the indexing rules. |
TypeScript Version: 2.4.2
Code
Workaround
Expected behavior:
Should compile
Actual behavior:
There is an issue #11773 demonstrating it with a "normal" enum.
The text was updated successfully, but these errors were encountered: