-
Notifications
You must be signed in to change notification settings - Fork 13k
Closed
Labels
FixedA PR has been merged for this issueA PR has been merged for this issueSuggestionAn idea for TypeScriptAn idea for TypeScript
Milestone
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.
falfiya, afeinman and IKoshelev
Metadata
Metadata
Assignees
Labels
FixedA PR has been merged for this issueA PR has been merged for this issueSuggestionAn idea for TypeScriptAn idea for TypeScript