sindresorhus/type-fest

Proposal: `AsyncFunction`

Open

#121 opened on Aug 18, 2020

View on GitHub
 (22 comments) (2 reactions) (0 assignees)TypeScript (471 forks)batch import
corehelp wantedtype addition

Repository metrics

Stars
 (12,328 stars)
PR merge metrics
 (Avg merge 3d 5h) (11 merged PRs in 30d)

Description

To make it easier to constrain a type to be an async function. We can currently do T extends Function, but there's no way to enforce it to be async.

We already have an internal type for this:

https://github.com/sindresorhus/type-fest/blob/78019f42ea888b0cdceb41a4a78163868de57555/source/async-return-type.d.ts#L3

But I'm thinking it could be more reusable:

type AsyncFunction<Arguments extends readonly any[] = readonly any[], ReturnValue = unknown> = (...arguments_: Arguments) => Promise<ReturnValue>;

Thoughts?

Contributor guide