Sha256: ff1731974600a4dad7ec87770e95fc86ca3d329b1ce200032766340f83585e47
Contents?: true
Size: 1.19 KB
Versions: 28
Compression:
Stored size: 1.19 KB
Contents
import type {SetReturnType} from './set-return-type'; /** Create an async version of the given function type, by boxing the return type in `Promise` while keeping the same parameter types. Use-case: You have two functions, one synchronous and one asynchronous that do the same thing. Instead of having to duplicate the type definition, you can use `Asyncify` to reuse the synchronous type. @example ``` import type {Asyncify} from 'type-fest'; // Synchronous function. function getFooSync(someArg: SomeType): Foo { // … } type AsyncifiedFooGetter = Asyncify<typeof getFooSync>; //=> type AsyncifiedFooGetter = (someArg: SomeType) => Promise<Foo>; // Same as `getFooSync` but asynchronous. const getFooAsync: AsyncifiedFooGetter = (someArg) => { // TypeScript now knows that `someArg` is `SomeType` automatically. // It also knows that this function must return `Promise<Foo>`. // If you have `@typescript-eslint/promise-function-async` linter rule enabled, it will even report that "Functions that return promises must be async.". // … } ``` @category Async */ export type Asyncify<Function_ extends (...arguments_: any[]) => any> = SetReturnType<Function_, Promise<Awaited<ReturnType<Function_>>>>;
Version data entries
28 entries across 28 versions & 2 rubygems