String literal type from string template #14584
Labels
Awaiting More Feedback
This means we'd like to hear from more people who would be helped by this feature
Suggestion
An idea for TypeScript
TypeScript Version: 2.1.5
Code
I frequently run into situations where I have a computed key from another key, both of which are string literals:
Expected behavior:
Since
z.${Key}
can only be valid literal values ofCombinedKey
it would be helpful if it compiled without error.Actual behavior:
Error
Type 'string' is not assignable to type 'CombinedKey'
.I can workaround using an assertion:
But this allows
Key
orCombinedKey
to become incompatible without a compile error:The text was updated successfully, but these errors were encountered: