String to Union
提出詳細
type Split<T extends string> = T extends `${infer First}${infer Rest}` ? [First, ...Split<Rest>] : [] type StringToUnion<T extends string> = Split<T>[number]
提出日時 | 2023-08-11 11:56:39 |
---|---|
問題 | String to Union |
ユーザー | tekihei2317 |
ステータス | 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'>>, ]