Sha256: 6e95aab5b3ba30cdbc9d4ad350ae7cbeb519a1eda30a214d2b1ec1f53eecdf9c

Contents?: true

Size: 1.19 KB

Versions: 62

Compression:

Stored size: 1.19 KB

Contents

import {PromiseValue} from './promise-value';
import {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 {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.".

	// …
}
```
*/
export type Asyncify<Fn extends (...args: any[]) => any> = SetReturnType<Fn, Promise<PromiseValue<ReturnType<Fn>>>>;

Version data entries

62 entries across 62 versions & 5 rubygems

Version Path
immosquare-cleaner-0.1.19 node_modules/type-fest/source/asyncify.d.ts
immosquare-cleaner-0.1.18 node_modules/type-fest/source/asyncify.d.ts
immosquare-cleaner-0.1.17 node_modules/type-fest/source/asyncify.d.ts
immosquare-cleaner-0.1.16 node_modules/type-fest/source/asyncify.d.ts
immosquare-cleaner-0.1.14 node_modules/type-fest/source/asyncify.d.ts
immosquare-cleaner-0.1.13 node_modules/type-fest/source/asyncify.d.ts
immosquare-cleaner-0.1.12 node_modules/type-fest/source/asyncify.d.ts
immosquare-cleaner-0.1.11 node_modules/type-fest/source/asyncify.d.ts
immosquare-cleaner-0.1.10 node_modules/type-fest/source/asyncify.d.ts
immosquare-cleaner-0.1.9 node_modules/type-fest/source/asyncify.d.ts
immosquare-cleaner-0.1.8 node_modules/type-fest/source/asyncify.d.ts
immosquare-cleaner-0.1.7 node_modules/type-fest/source/asyncify.d.ts
immosquare-cleaner-0.1.6 node_modules/type-fest/source/asyncify.d.ts
decidim-0.26.8 packages/eslint-config/node_modules/type-fest/source/asyncify.d.ts
reed_sdk-1.0.1 node_modules/type-fest/source/asyncify.d.ts
reed_sdk-1.0.0 node_modules/type-fest/source/asyncify.d.ts
decidim-0.27.1 packages/webpacker/node_modules/type-fest/source/asyncify.d.ts
decidim-0.26.4 packages/webpacker/node_modules/type-fest/source/asyncify.d.ts
decidim-0.27.0 packages/webpacker/node_modules/type-fest/source/asyncify.d.ts
decidim-0.26.3 packages/webpacker/node_modules/type-fest/source/asyncify.d.ts