generated from garronej/ts-ci
-
Notifications
You must be signed in to change notification settings - Fork 6
/
UnpackPromise.ts
43 lines (33 loc) 路 966 Bytes
/
UnpackPromise.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
/* eslint-disable @typescript-eslint/no-explicit-any */
/* eslint-disable @typescript-eslint/no-unused-vars */
/* eslint-disable @typescript-eslint/ban-ts-comment */
import type { UnpackPromise } from "../UnpackPromise.ts";
import { assert } from "../assert.ts";
import type { Equals } from "../Equals.ts";
//@ts-ignore
function test<T>() {
const prT = new Promise<T>(resolve => setTimeout(resolve, 1));
type Expected = T;
type Got = UnpackPromise<typeof prT>;
assert<Equals<Got, Expected>>();
}
//@ts-ignore
function test<T>() {
const f = async () => {
const out: T = null as any;
return out;
};
const prT = f();
type Expected = T;
type Got = UnpackPromise<typeof prT>;
assert<Equals<Got, Expected>>();
}
{
type Got = UnpackPromise<undefined | null | false | "">;
type Expected = never;
assert<Equals<Got, Expected>>();
}
{
//@ts-expect-error
type Got = UnpackPromise<string>;
}