forked from microsoft/TypeScript
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpromiseTry.js
64 lines (57 loc) · 2.31 KB
/
promiseTry.js
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
//// [tests/cases/compiler/promiseTry.ts] ////
//// [promiseTry.ts]
Promise.try(() => {
return "Sync result";
});
Promise.try(async () => {
return "Async result";
});
const a = Promise.try(() => "Sync result");
const b = Promise.try(async () => "Async result");
// SINGLE PARAMETER
Promise.try((foo: string) => "Async result", "foo");
Promise.try((foo) => "Async result", "foo");
// @ts-expect-error too few parameters
Promise.try((foo) => "Async result");
Promise.try((foo: string | undefined) => "Async result", undefined);
Promise.try((foo: string | undefined) => "Async result", "foo");
Promise.try((foo) => "Async result", undefined);
// @ts-expect-error too many parameters
Promise.try(() => "Async result", "foo");
// MULTIPLE PARAMETERS
Promise.try((foo: string, bar: number) => "Async result", "foo", 42);
// @ts-expect-error too many parameters
Promise.try((foo: string, bar: number) => "Async result", "foo", 42, "baz");
// @ts-expect-error too few parameters
Promise.try((foo: string, bar: number) => "Async result", "foo");
Promise.try((foo: string, bar?: number) => "Async result", "foo");
Promise.try((foo: string, bar?: number) => "Async result", "foo", undefined);
Promise.try((foo: string, bar?: number) => "Async result", "foo", 42);
//// [promiseTry.js]
Promise.try(() => {
return "Sync result";
});
Promise.try(async () => {
return "Async result";
});
const a = Promise.try(() => "Sync result");
const b = Promise.try(async () => "Async result");
// SINGLE PARAMETER
Promise.try((foo) => "Async result", "foo");
Promise.try((foo) => "Async result", "foo");
// @ts-expect-error too few parameters
Promise.try((foo) => "Async result");
Promise.try((foo) => "Async result", undefined);
Promise.try((foo) => "Async result", "foo");
Promise.try((foo) => "Async result", undefined);
// @ts-expect-error too many parameters
Promise.try(() => "Async result", "foo");
// MULTIPLE PARAMETERS
Promise.try((foo, bar) => "Async result", "foo", 42);
// @ts-expect-error too many parameters
Promise.try((foo, bar) => "Async result", "foo", 42, "baz");
// @ts-expect-error too few parameters
Promise.try((foo, bar) => "Async result", "foo");
Promise.try((foo, bar) => "Async result", "foo");
Promise.try((foo, bar) => "Async result", "foo", undefined);
Promise.try((foo, bar) => "Async result", "foo", 42);