Type Alias StringSplit<Subject, Seperator>

StringSplit<Subject, Seperator>: Subject extends `${infer A}${Seperator}${infer B}`
    ? [A, ...StringSplit<B, Seperator>]
    : Seperator extends ""
        ? []
        : [Subject]

Split a string into substrings using the specified separator, and return them as an array.

type R = StringSplit<'abc', ''> // ['a', 'b', 'c']
type R = StringSplit<'abc', 'a'> // ['', 'bc']
type R = StringSplit<'abc', 'b'> // ['a', 'c']
type R = StringSplit<'abc', 'c'> // ['ab', '']

Type Parameters

  • Subject extends string
  • Seperator extends string