'TypeScript `extend` produces ESLint error when extending a template string?
I want to implement a type TrimStart like this:
type TrimStart<T extends string> = T extends ` ${infer Rest}` ? TrimStart<Rest> : T;
type TT = TrimStart<' Vue React Angular'>; // 'Vue React Angular'
But this produces the following error: Parsing error: Type expected.eslint
Solution 1:[1]
You forgot to declare the generic parameter T
.
type TrimStart<T> = T extends ` ${infer Rest}` ? TrimStart<Rest> : T;
type TT = TrimStart<' Vue React Angular'>
// type TT = "Vue React Angular"
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | marc_s |