UNPKG

rivo

Version:

🤖 The ultimate library you need for composable type-level programming in TypeScript, powered by HKT.

25 lines (22 loc) • 631 B
import type { Args, Fn } from "../HKT"; import type { List } from "../List"; import type { Assert } from "../helpers"; /** * Returns a list of characters of a string. * * Sig: `(s: string) => List<string>` */ export type ToChars<S extends string> = Assert< List<string>, string extends S ? List<string> : S extends `${infer Head}${infer Tail}` ? readonly [Head, ...ToChars<Tail>] : readonly [] >; /** * [Fn] Returns a list of characters of a string. * * Sig: `(s: string) => List<string>` */ export default interface ToCharsFn extends Fn<[string], List<string>> { def: ([s]: Args<this>) => ToChars<typeof s>; }