rivo
Version:
🤖 The ultimate library you need for composable type-level programming in TypeScript, powered by HKT.
23 lines (20 loc) • 530 B
TypeScript
import type { Args, Fn1 } from "../HKT";
import type { Nat } from "../Num";
import type { Inc } from "../Num/Int/Inc";
import type { AssertNat } from "../helpers";
/**
* Get the length of a string.
*
* Sig: `(s: string) => Nat`
*/
export type Length<S extends string> = AssertNat<
S extends `${string}${infer R}` ? Inc<Length<R>> : 0
>;
/**
* [Fn] Get the length of a string.
*
* Sig: `(s: string) => Nat`
*/
export default interface LengthFn extends Fn1<string, Nat> {
def: ([s]: Args<this>) => Length<typeof s>;
}