You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
typeNumbers={[numberToParse: `number_${string}`]: (num: typeofnumberToParse)=>number;};consta: Numbers={// Because of the `Numbers` type, typescript// should know that `num` is "number_three".// Instead, `num` is said to be a template,// So number_three fails to compile.number_three(num: "number_three"){return3;},};
The text was updated successfully, but these errors were encountered:
esthedebeste
changed the title
typeof returns the template instead of the actual string.
typeof returns the template instead of the actual string
Oct 7, 2021
You would need a way to encode type parameters on index signatures, or some similar feature, which is discussed a bit over at #22509. Right now, we don't have any way of saying that an index signature is generic.
Bug Report
π Search Terms
typeof key, typeof template, template key
β― Playground Link
`number_${string}` cannot be assigned to "number_three", even though that will be the value.
π» Code
A shorter example:
Though this could simply use generics
π Actual behavior
The
num
variable is annotated"number_${string}"
π Expected behavior
The
num
variable is annotated"number_three"
The text was updated successfully, but these errors were encountered: