-
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
Cannot infer Template Literal Type containing ${number}
/ ${string}
🔎 Search Terms
- Template Literal Types number infer
- Template Literal Types string infer
🕗 Version & Regression Information
- This is the behavior of version 4.1 or higher.
⏯ Playground Link
Playground link with relevant code
💻 Code
// ${number} issue
type A<T> = T extends `${infer U}.${infer V}` ? U | V : never
type B = A<`test.1024`>; // This will be "test" | "1024" as expected
type C = A<`test.${number}`>; // Expected "test" | `${number}` or "test" | number but this will be never
type D<T> = T extends `${infer U}.${number}` ? U : never
type E = D<`test.1024`>; // This will be "test" as expected
type F = D<`test.${number}`>; // Expected "test" but this will be never
// ${string} issue
type G<T> = T extends `${infer U}.${infer V}` ? U | V : never
type H = G<`test.hoge`>; // This will be "test" | "hoge" as expected
type I = G<`test.${string}`>; // Expected "test" | `${string}` or "test" | string but this will be never
type J<T> = T extends `${infer U}.${string}` ? U : never
type K = J<`test.hoge`>; // This will be "test" as expected
type L = J<`test.${string}`>; // Expected "test" but this will be never
🙁 Actual behavior
C
type isnever
.F
type isnever
.I
type isnever
.L
type isnever
.
🙂 Expected behavior
- Expected
C
type to be"test" | `${number}`
or"test" | number
. - Expected
F
type to be"test"
. - Expected
I
type to be"test" | `${string}`
or"test" | string
. - Expected
L
type to be"test"
.
bluebill1049, peterboyer, siefkenj and dylan-oleria
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