-
-
Notifications
You must be signed in to change notification settings - Fork 505
/
asyncify.ts
20 lines (16 loc) · 821 Bytes
/
asyncify.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
import {expectTypeOf} from 'expect-type';
import type {Asyncify} from '../index';
declare function getFooSync(name: string): RegExp;
declare function getFooWithThisArgSync(this: Date, name: string): RegExp;
// Basic usage.
declare const getFooAsync1: Asyncify<typeof getFooSync>;
expectTypeOf(getFooAsync1).toEqualTypeOf<(name: string) => Promise<RegExp>>();
// Noops with async functions.
declare const getFooAsync2: Asyncify<typeof getFooAsync1>;
expectTypeOf(getFooAsync2).toEqualTypeOf<typeof getFooAsync1>();
// Respects `thisArg`.
declare const getFooWithThisArgAsync1: Asyncify<typeof getFooWithThisArgSync>;
const callResult = getFooWithThisArgAsync1.call(new Date(), 'foo');
expectTypeOf(callResult).toEqualTypeOf<Promise<RegExp>>();
// @ts-expect-error
void getFooWithThisArgAsync1.call('not-date', 'foo');