@api-buddy/types
Version:
Shared types for API Buddy
121 lines • 3.91 kB
TypeScript
/**
* Utility Types
*
* This file contains shared utility types used across the API Buddy ecosystem.
*/
/**
* A type that makes all properties optional, recursively
*/
export type DeepPartial<T> = T extends object ? {
[P in keyof T]?: DeepPartial<T[P]>;
} : T;
/**
* A type that makes all properties required, recursively
*/
export type DeepRequired<T> = T extends object ? {
[P in keyof T]-?: DeepRequired<T[P]>;
} : T;
/**
* A type that makes all properties readonly, recursively
*/
export type DeepReadonly<T> = T extends object ? {
readonly [P in keyof T]: DeepReadonly<T[P]>;
} : T;
/**
* A type that makes all properties mutable, recursively
*/
export type DeepMutable<T> = T extends object ? {
-readonly [P in keyof T]: DeepMutable<T[P]>;
} : T;
/**
* A type that represents a constructor function
*/
export type Constructor<T = {}> = new (...args: any[]) => T;
/**
* A type that represents a class with a static create method
*/
export type Factory<T, Args extends any[] = any[]> = {
new (...args: Args): T;
create(...args: Args): T;
};
/**
* A type that represents a dictionary/map with string keys
*/
export type Dictionary<T> = Record<string, T>;
/**
* A type that represents a value that can be null or undefined
*/
export type Nullable<T> = T | null | undefined;
/**
* A type that represents a value that can be a promise or not
*/
export type Awaitable<T> = T | Promise<T>;
/**
* A type that represents a function that returns a value or a promise of that value
*/
export type MaybePromise<T> = T | Promise<T>;
/**
* A type that represents a function that takes no arguments and returns a value
*/
export type Supplier<T> = () => T;
/**
* A type that represents a function that takes a value and returns void
*/
export type Consumer<T> = (value: T) => void;
/**
* A type that represents a function that transforms a value
*/
export type Mapper<T, R = T> = (value: T) => R;
/**
* A type that represents a predicate function
*/
export type Predicate<T> = (value: T) => boolean;
/**
* A type that represents a comparator function
*/
export type Comparator<T> = (a: T, b: T) => number;
/**
* A type that represents a function that can be called with any arguments and returns any value
*/
export type AnyFunction = (...args: any[]) => any;
/**
* A type that represents a function that takes no arguments and returns void
*/
export type Action = () => void;
/**
* A type that represents a function that takes one argument and returns void
*/
export type Action1<T> = (arg: T) => void;
/**
* A type that represents a function that takes two arguments and returns void
*/
export type Action2<T1, T2> = (arg1: T1, arg2: T2) => void;
/**
* A type that represents a function that takes three arguments and returns void
*/
export type Action3<T1, T2, T3> = (arg1: T1, arg2: T2, arg3: T3) => void;
/**
* A type that represents a function that takes no arguments and returns a boolean
*/
export type Func0<TReturn> = () => TReturn;
/**
* A type that represents a function that takes one argument and returns a value
*/
export type Func1<T, TReturn> = (arg: T) => TReturn;
/**
* A type that represents a function that takes two arguments and returns a value
*/
export type Func2<T1, T2, TReturn> = (arg1: T1, arg2: T2) => TReturn;
/**
* A type that represents a function that takes three arguments and returns a value
*/
export type Func3<T1, T2, T3, TReturn> = (arg1: T1, arg2: T2, arg3: T3) => TReturn;
/**
* A type that represents a function that takes four arguments and returns a value
*/
export type Func4<T1, T2, T3, T4, TReturn> = (arg1: T1, arg2: T2, arg3: T3, arg4: T4) => TReturn;
/**
* A type that represents a function that takes five arguments and returns a value
*/
export type Func5<T1, T2, T3, T4, T5, TReturn> = (arg1: T1, arg2: T2, arg3: T3, arg4: T4, arg5: T5) => TReturn;
//# sourceMappingURL=index.d.ts.map