-
Notifications
You must be signed in to change notification settings - Fork 12.6k
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
Template Literal Type - Does not evaluate interpolated template strings against type definition #41732
Comments
Related issues: #40707, #10676 From #40707, if you use a const pixelValue: number = 22;
type PixelValueType = `${number}px`;
const pixelStringWithTemplate: PixelValueType = `${pixelValue}px` as const; // okay It looks like your desired behavior is for the compiler to always synthesize a template literal type for a template literal expression the way #10676 does for other literal types, so that |
Why the |
@ahejlsberg Seems like we should be providing a literal context here? |
This is a duplicate of #41631. |
Now implemented in #41891. |
TypeScript Version: 4.1.2
Search Terms:
template literal type template string interpolation number pixel value
Code
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 TypePlayground Link:
https://www.typescriptlang.org/play?#code/MYewdgzgLgBADgSwB4FMA2A1AhmgrigLhjFwFsAjFAJxgF4YAmBgbgChWoBPOFGABWTpseFABVuvegAMAJAG8SFagF84SKW1ahIsRKjQBlKFQRgA5kQH7h+cTzowpTNRq3ho8QYeOmzAdQQoAAtRFFI4NCwoQn4vGzEJB1k5PSEcfFV1NiA
Related Issues:
The text was updated successfully, but these errors were encountered: