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
typeFoo='{id}/bar';functionfoo(num: number) : Foo{return`${num}/bar`as'{id}/bar'// Workaround// return `${num}/bar` as string as '{id}/bar'}// Also okayfunctionfoo(num: string/*change to string*/) : Foo{return`${num}/bar`as'{id}/bar';}
π Actual behaviour
Error:
Conversion of type '${number}/bar' to type '"{id}/bar"' may be a mistake because neither type sufficiently overlaps with the other. If this was intentional, convert the expression to 'unknown' first.
π Expected behaviour
No Error
Remarks
This is quite a large breaking change that we are experiencing.
It's not mentioned in the 'breaking changes' of the release notes.
It's not clear why this should be an error.
The workaround of having a type assertion for string seems pretty useless as toString on a number is always a faithful representation of the number (that's the reasoning by which TypeScript allows for number to be used in Index Signatures).
The text was updated successfully, but these errors were encountered:
NoelAbrahams
changed the title
Number in Template Literal fails type assertion to Template Literal Type (4.5 Breaking Change)
Number in Template Literal fails type assertion to String Literal Type (4.5 Breaking Change)
Nov 22, 2021
Bug Report
π Search Terms
4.5 literal
π Version & Regression Information
This changed between versions 4.4 and 4.5
β― Playground Link
https://www.typescriptlang.org/play?ts=4.5.2#code/LAKALgngDgpgBAMQPZLgXjgcgN4EsAmAvgPQBGAhgE6YDcooAZgK4B2AxmLki3AygBQsmAWwBccIcNIxKASjjjkqbKDhq4q9ZRhgmlHgAMAJNkkkKlA3HIBnLHiJkqtTWuLFtu-XGOmR5qitbOBswSlwWAHNrOxwCAOo6EEIgA
π» Code
π Actual behaviour
Error:
π Expected behaviour
No Error
Remarks
string
seems pretty useless astoString
on a number is always a faithful representation of the number (that's the reasoning by which TypeScript allows for number to be used in Index Signatures).The text was updated successfully, but these errors were encountered: