/** Matches a [`class`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Classes). @category Class */ export type Class = { prototype: Pick; new(...arguments_: Arguments): T; }; /** Matches a [`class` constructor](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Classes). @category Class */ export type Constructor = new(...arguments_: Arguments) => T; /** Matches an [`abstract class`](https://www.typescriptlang.org/docs/handbook/2/classes.html#abstract-classes-and-members). @category Class @privateRemarks We cannot use a `type` here because TypeScript throws: 'abstract' modifier cannot appear on a type member. (1070) */ // eslint-disable-next-line @typescript-eslint/consistent-type-definitions export interface AbstractClass extends AbstractConstructor { prototype: Pick; } /** Matches an [`abstract class`](https://www.typescriptlang.org/docs/handbook/release-notes/typescript-4-2.html#abstract-construct-signatures) constructor. @category Class */ export type AbstractConstructor = abstract new(...arguments_: Arguments) => T; /** Matches an asynchronous function. Use-cases: - Constrain a generic type to an asynchronous function. - Declare a reusable asynchronous callback signature. @example ``` import type {AsyncFunction} from 'type-fest'; type FetchData = AsyncFunction<[url: URL], Uint8Array>; const fetchData: FetchData = async url => { const response = await fetch(url); return new Uint8Array(await response.arrayBuffer()); }; ``` @category Function @category Async */ export type AsyncFunction = (...arguments_: Arguments) => Promise; /** Matches any asynchronous function. Use-cases: - Constrain a generic type to any asynchronous function without prescribing its parameters or return value. @example ``` import type {AnyAsyncFunction} from 'type-fest'; function register(function_: FunctionType): FunctionType { return function_; } const getLength = register(async (value: string) => value.length); const result = getLength('unicorn'); //=> Promise ``` Note: A function with a `never` parameter, such as `(value: never) => Promise`, does not match. TypeScript skips the parameter check only for a function type that returns `unknown` or `any`. Use {@link AnyFunction} if you need to accept it. @category Function @category Async */ export type AnyAsyncFunction = (...arguments_: readonly any[]) => Promise; /** Matches any function. Use-cases: - Constrain a generic type to any function while erasing its parameters and return value. @example ``` import type {AnyFunction} from 'type-fest'; function identity(function_: FunctionType): FunctionType { return function_; } ``` @category Function */ export type AnyFunction = (...arguments_: readonly any[]) => unknown; export {};