Type alias Split<S, SEP, Acc>

Split<S, SEP, Acc>: string extends S
    ? S[]
    : S extends `${infer F}${SEP}${infer R}`
        ? Split<R, SEP, [...Acc, F]>
        : S extends ""
            ? SEP extends ""
                ? Acc
                : [""]
            : [...Acc, S]
  • A type that splits a string literal type S into an array of substrings using a separator SEP.

Type Parameters

  • S extends string
  • SEP extends string
  • Acc extends string[] = []

Example

Split<'', ''> // -> []
Split<'Hi! How are you?', 'z'> // -> ['Hi! How are you?']