Type Alias Prefixes<S, Acc>

Prefixes: S extends `${infer Head}${infer Tail}`
    ? `${Acc}${Head}`
    | Prefixes<Tail, `${Acc}${Head}`>
    : never

Generates all non-empty prefixes of a string literal type. E.g. Prefixes<"Order">"O" | "Or" | "Ord" | "Orde" | "Order". Distributes over unions: Prefixes<"A" | "B"> → prefixes of both.

Recursion limit: This type recurses once per character. TypeScript's template literal recursion limit is ~24 characters per string. Entity class names should stay under this limit to avoid "Type instantiation is excessively deep" errors.

Type Parameters

  • S extends string
  • Acc extends string = ""