Untitled
Anonymous
typescript
07/20/2024 8:18 PM
592 B
24
Indexable
// This is tricky because you cannot do Str extends `${infer Before}${UnionOfSep}${infer After}` ...
type Split<Str, UnionOfSep extends string, CurrentWord extends string = "", Output extends string[] = []> =
Str extends `${infer First}${infer Rest}`
? First extends UnionOfSep
? Split<Rest, UnionOfSep, "", [...Output, CurrentWord]>
: Split<Rest, UnionOfSep, `${CurrentWord}${First}`, Output>
: [...Output, CurrentWord];Editor is loading...
Leave a Comment