/** * Recursively make all properties optional */ type Primitive = string | number | boolean | bigint | symbol | null | undefined; type Builtin = Primitive | Date | Error | RegExp; export type RecursivePartial = // stop on built-ins (incl. Error) and functions T extends Builtin ? T : // arrays and readonly arrays T extends ReadonlyArray ? ReadonlyArray> : T extends Array ? Array> : // (optionally: Map/Set support) T extends Map ? Map, RecursivePartial> : T extends Set ? Set> : // plain objects T extends object ? {[P in keyof T]?: RecursivePartial} : // fallback (shouldn’t be hit often) T; /** Type safe wrapper for Number constructor that takes 'any' */ export function bnToNum(bn: bigint): number { return Number(bn); } export type NonEmptyArray = [T, ...T[]]; /** * ArrayToTuple converts an `Array` to `[T, ...T]` * * eg: `[1, 2, 3]` from type `number[]` to `[number, number, number]` */ export type ArrayToTuple> = { [Index in keyof Tuple]: Tuple[Index]; }; /** * Convert optional attributes of an object to required */ export type RequiredSelective = T & { [K in Keys]-?: T[K]; };