/** A non-empty readonly array; the type system guarantees index 0 exists. */ export type NonEmptyArray = readonly [T, ...T[]] /** Values that round-trip through JSON.stringify / JSON.parse. */ export type JsonValue = | string | number | boolean | null | readonly JsonValue[] | { readonly [key: string]: JsonValue | undefined } /** Element type of a readonly array (e.g., `ElementOf`). */ export type ElementOf = T extends readonly (infer E)[] ? E : never /** Deep-readonly version of a structural type. */ export type DeepReadonly = T extends (infer U)[] ? ReadonlyArray> : T extends Map ? ReadonlyMap, DeepReadonly> : T extends Set ? ReadonlySet> : T extends object ? { readonly [K in keyof T]: DeepReadonly } : T /** * Nominal / branded type: compile-time-only tag to distinguish otherwise * structurally-equal types. * * type PersonId = Brand * type RelId = Brand * * PersonId and RelId are still strings at runtime but aren't assignable * to each other without an explicit cast. */ export type Brand = T & { readonly __brand: B }