String to Union
提出詳細
type StringToUnion<T extends string, C extends readonly string[] = []> = T extends `${infer F}${infer Tail}` ? StringToUnion<Tail, [...C, F]>: C[number]
提出日時 | 2022-06-27 23:22:32 |
---|---|
問題 | String to Union |
ユーザー | waki285 |
ステータス | Accepted |
import type { Equal, Expect } from '@type-challenges/utils' type cases = [ Expect<Equal<StringToUnion<''>, never>>, Expect<Equal<StringToUnion<'t'>, 't'>>, Expect<Equal<StringToUnion<'hello'>, 'h' | 'e' | 'l' | 'l' | 'o'>>, Expect<Equal<StringToUnion<'coronavirus'>, 'c' | 'o' | 'r' | 'o' | 'n' | 'a' | 'v' | 'i' | 'r' | 'u' | 's'>>, ]