// --- Async helpers --- /** A value that may or may not be wrapped in a Promise */ export type MaybePromise = T | Promise; /** Extract the resolved type from a Promise */ export type Awaited = T extends Promise ? U : T; // --- Object helpers --- /** Flatten an intersection into a single object type (improves IDE display) */ export type Prettify = { [K in keyof T]: T[K]; } & {}; /** Make specific keys required */ export type RequireKeys = Prettify & Required>>; /** Make specific keys optional */ export type OptionalKeys = Prettify & Partial>>; /** Extract keys whose values extend a given type */ export type KeysMatching = { [K in keyof T]-?: T[K] extends V ? K : never; }[keyof T]; // --- String helpers --- /** Enforce a string starts with a given prefix */ export type StringWithPrefix

= `${P}${string}`; /** KV key with prefix — e.g., StringWithPrefix<'user:'> */ export type PrefixedKey

= StringWithPrefix

; // --- Tuple helpers --- /** A non-empty array */ export type NonEmptyArray = [T, ...T[]]; // --- Exhaustive check --- /** Use in switch default to get compile error if a case is missed */ export function assertNever(value: never): never { throw new Error(`Unexpected value: ${value}`); } // --- Record helpers --- /** Like Record but with better inference */ export type Dict = Record; /** A readonly dictionary */ export type ReadonlyDict = Readonly>;