/// /** Makes specified properties required in a type */ export type WithRequired = T & { [P in K]-?: T[P]; }; /** Makes specified properties optional in a type */ export type WithOptional = Omit & Partial>; /** Signifies that the value can be undefined */ export type Optional = T | undefined; /** * Native `Omit` has some known bugs which are not going to be fixed, as it can break backward compatibility, so here * is a modern fixed version (https://stackoverflow.com/questions/76616163/omit-seems-broken-on-type-extending-record) */ export type Omit = { [P in keyof T as Exclude]: T[P]; }; /** * Creates a type as one of const array elements. * * @example * const TIME_UNITS = ['hours', 'minutes', 'seconds'] as const; * type TimeUnit = OneOf; */ export type OneOf = T extends readonly (infer K)[] ? K : never; /** Deeply replaces `Date` and `Buffer` fields to their JSON representation in a type */ export type Serialized = { [P in keyof T]: T[P] extends Date ? string : T[P] extends Buffer ? { type: 'Buffer'; data: number[]; } : Serialized; }; /** Signifies that a type can be wrapped in a promise */ export type PromiseOrNot = Promise | T; /** Constructor function */ export type Constructor = { new (...args: Args): T; }; /** Extracts method names of a class */ export type MethodNames = { [K in keyof T]: T[K] extends (...args: any[]) => any ? K : never; }[keyof T]; /** * Replaces a key type * * @example * type ExampleType = {a: number, b: string}; * type ReplacedType = Replace; */ export type Replace = { [P in keyof T]: P extends keyof Replacements ? Replacements[P] : T[P]; }; /** Like `Partial` but deep */ export type DeepPartial = T extends object ? T extends Date ? T : { [P in keyof T]?: DeepPartial; } : T; /** Like `Required` but deep */ export type RequiredDeep = T extends object ? T extends Date ? T : { [P in keyof T]-?: RequiredDeep; } : T; /** Selects only public members of a class */ export type Public = { [K in keyof T]: T[K]; }; /** Shortened `Record` where keys are always strings */ export type Dict = Record; type TupleSplit = Acc['length'] extends N ? [Acc, T] : T extends readonly [infer Head, ...infer Tail] ? TupleSplit : [Acc, []]; /** Skips the first N elements of a tuple */ export type SkipFirst = TupleSplit[1]; /** * Calls `bind` on function saving original function type * @param func function to bind * @param thisArg `this` argument * @returns bound function */ export declare function typedBind(func: T, thisArg: any): T; export {};