Closed
Description
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.