Cannot infer Template Literal Type containing ${number}
/ ${string}
· Issue #43060 · microsoft/TypeScript (original) (raw)
Navigation Menu
- Explore
- Pricing
Provide feedback
Saved searches
Use saved searches to filter your results more quickly
Appearance settings
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 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 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 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 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"
.