UNPKG

@dvcol/common-utils

Version:

Typescript library for common utility functions and constants

37 lines (35 loc) 1.32 kB
/** * Extends Partial to make all own properties also Partial */ type RecursivePartial<T> = { [P in keyof T]?: RecursivePartial<T[P]> | T[P]; }; type RequireAtLeastOne<T> = { [K in keyof T]-?: Required<Pick<T, K>> & Partial<Pick<T, Exclude<keyof T, K>>>; }[keyof T]; type ExclusiveUnion<T> = { [K in keyof T]: { [P in K]: T[K]; }; }[keyof T]; type Primitive = string | boolean | number; type PrimitiveRecord = Record<string, Primitive>; type RecursiveRecord<T = any> = { [key: string]: T | RecursiveRecord<T>; } | Record<string, never>; type GenericFunction = (...args: any) => any; type ArrayElement<ArrayType extends readonly unknown[] | undefined> = ArrayType extends readonly (infer ElementType)[] ? ElementType : never; type RecursiveType<T, R> = { [K in keyof T]: T[K] extends object ? RecursiveType<T[K], R> : R; }; type Mutable<T> = { -readonly [P in keyof T]: T[P]; }; type SyncOrAsync<T> = T | Promise<T>; type Prettify<T> = { [K in keyof T]: T[K]; } & {}; type DeepPrettify<T> = { [K in keyof T]: T[K] extends object ? DeepPrettify<T[K]> : T[K]; } & {}; export type { ArrayElement, DeepPrettify, ExclusiveUnion, GenericFunction, Mutable, Prettify, Primitive, PrimitiveRecord, RecursivePartial, RecursiveRecord, RecursiveType, RequireAtLeastOne, SyncOrAsync };