TypeScript Version: 4.1.2
Search Terms:
template literal type template string interpolation number pixel value
Code
const pixelValue: number = 22;
type PixelValueType = `${number}px`;
const pixelString: PixelValueType = `22px`;
// Error here
const pixelStringWithTemplate: PixelValueType = `${pixelValue}px`;
Expected behavior:
A template string should be evaluated to determine if it matches a template literal type.
Actual behavior:
The template string is evaluated to type string even though it can match the Template Literal Type
Type 'string' is not assignable to type '`${number}px`'.(2322)
Playground Link:
https://www.typescriptlang.org/play?#code/MYewdgzgLgBADgSwB4FMA2A1AhmgrigLhjFwFsAjFAJxgF4YAmBgbgChWoBPOFGABWTpseFABVuvegAMAJAG8SFagF84SKW1ahIsRKjQBlKFQRgA5kQH7h+cTzowpTNRq3ho8QYeOmzAdQQoAAtRFFI4NCwoQn4vGzEJB1k5PSEcfFV1NiA
Related Issues: