挑战
实现一个将接收到的 String 参数转换为一个字母 Union 的类型。
例如
type Test = '123';
type Result = StringToUnion<Test>; // expected to be "1" | "2" | "3"解答
这道题我们需要遍历字符串,把每个字符加到联合类型中。
type StringToUnion<T extends string> = T extends `${infer F}${infer R}`
? F | StringToUnion<R>
: never;