type-fest/source/basic.d.ts
Sindre Sorhus 49d0db8986 Add Constructor type
Fixes #155
2021-08-06 02:02:57 +02:00

37 lines
1.2 KiB
TypeScript

/**
Matches a [`class`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Classes).
@category Basic
*/
export type Class<T, Arguments extends unknown[] = any[]> = Constructor<T, Arguments> & {prototype: T};
/**
Matches a [`class` constructor](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Classes).
@category Basic
*/
export type Constructor<T, Arguments extends unknown[] = any[]> = new(...arguments_: Arguments) => T;
/**
Matches a JSON object.
This type can be useful to enforce some input to be JSON-compatible or as a super-type to be extended from. Don't use this as a direct return type as the user would have to double-cast it: `jsonObject as unknown as CustomResponse`. Instead, you could extend your CustomResponse type from it to ensure your type only uses JSON-compatible types: `interface CustomResponse extends JsonObject { … }`.
@category Basic
*/
export type JsonObject = {[Key in string]?: JsonValue};
/**
Matches a JSON array.
@category Basic
*/
export type JsonArray = JsonValue[];
/**
Matches any valid JSON value.
@category Basic
*/
export type JsonValue = string | number | boolean | null | JsonObject | JsonArray;