// from a library
type T = null | "auto" | "text0" | "text1" | "text2" | "text3" | "text4";
//in my code
type N = Extract<T, `text${number}`> extends `text${infer R}` ? R : never
Run Code Online (Sandbox Code Playgroud)
(TS游乐场)
对于上面的代码段N将相当于"0" | "1" | "2" | "3" | "4". 我怎样才能将其转换为数字类型,即0 | 1 | 2 | 3 | 4?已经尝试 & number在某些地方放置,例如infer R & number,但都不起作用。