Template literal expression is not assignable to matching template literal type · Issue #43243 · microsoft/TypeScript (original) (raw)
Bug Report
🔎 Search Terms
template literal types, template literal assignability
🕗 Version & Regression Information
- This is the behavior in every version I tried, and I reviewed the FAQ for entries about template literal types.
⏯ Playground Link
Playground link with relevant code
💻 Code
type Templated = ${string} ${string}
;
const value1: string = "abc";
const templated1: Templated = ${value1} abc
as const;
// Type '${string} abc
' is not assignable to type '${string} ${string}
'.
const value2 = "abc";
const templated2: Templated = ${value2} abc
as const;
Note in the second case, where value2
is a literal string, the assignment works okay.
🙁 Actual behavior
Type '`${string} abc`' is not assignable to type '`${string} ${string}`'.
🙂 Expected behavior
I would expect this value to be assignable, since the statically known value type matches the template pattern.
It is also odd that the two cases above behave differently.