|
| 1 | +//// [tests/cases/compiler/promiseTry.ts] //// |
| 2 | + |
| 3 | +//// [promiseTry.ts] |
| 4 | +Promise.try(() => { |
| 5 | + return "Sync result"; |
| 6 | +}); |
| 7 | + |
| 8 | +Promise.try(async () => { |
| 9 | + return "Async result"; |
| 10 | +}); |
| 11 | + |
| 12 | +const a = Promise.try(() => "Sync result"); |
| 13 | +const b = Promise.try(async () => "Async result"); |
| 14 | + |
| 15 | +// SINGLE PARAMETER |
| 16 | +Promise.try((foo: string) => "Async result", "foo"); |
| 17 | +Promise.try((foo) => "Async result", "foo"); |
| 18 | +// @ts-expect-error too few parameters |
| 19 | +Promise.try((foo) => "Async result"); |
| 20 | +Promise.try((foo: string | undefined) => "Async result", undefined); |
| 21 | +Promise.try((foo: string | undefined) => "Async result", "foo"); |
| 22 | +Promise.try((foo) => "Async result", undefined); |
| 23 | +// @ts-expect-error too many parameters |
| 24 | +Promise.try(() => "Async result", "foo"); |
| 25 | + |
| 26 | +// MULTIPLE PARAMETERS |
| 27 | +Promise.try((foo: string, bar: number) => "Async result", "foo", 42); |
| 28 | +// @ts-expect-error too many parameters |
| 29 | +Promise.try((foo: string, bar: number) => "Async result", "foo", 42, "baz"); |
| 30 | +// @ts-expect-error too few parameters |
| 31 | +Promise.try((foo: string, bar: number) => "Async result", "foo"); |
| 32 | +Promise.try((foo: string, bar?: number) => "Async result", "foo"); |
| 33 | +Promise.try((foo: string, bar?: number) => "Async result", "foo", undefined); |
| 34 | +Promise.try((foo: string, bar?: number) => "Async result", "foo", 42); |
| 35 | + |
| 36 | + |
| 37 | +//// [promiseTry.js] |
| 38 | +Promise.try(() => { |
| 39 | + return "Sync result"; |
| 40 | +}); |
| 41 | +Promise.try(async () => { |
| 42 | + return "Async result"; |
| 43 | +}); |
| 44 | +const a = Promise.try(() => "Sync result"); |
| 45 | +const b = Promise.try(async () => "Async result"); |
| 46 | +// SINGLE PARAMETER |
| 47 | +Promise.try((foo) => "Async result", "foo"); |
| 48 | +Promise.try((foo) => "Async result", "foo"); |
| 49 | +// @ts-expect-error too few parameters |
| 50 | +Promise.try((foo) => "Async result"); |
| 51 | +Promise.try((foo) => "Async result", undefined); |
| 52 | +Promise.try((foo) => "Async result", "foo"); |
| 53 | +Promise.try((foo) => "Async result", undefined); |
| 54 | +// @ts-expect-error too many parameters |
| 55 | +Promise.try(() => "Async result", "foo"); |
| 56 | +// MULTIPLE PARAMETERS |
| 57 | +Promise.try((foo, bar) => "Async result", "foo", 42); |
| 58 | +// @ts-expect-error too many parameters |
| 59 | +Promise.try((foo, bar) => "Async result", "foo", 42, "baz"); |
| 60 | +// @ts-expect-error too few parameters |
| 61 | +Promise.try((foo, bar) => "Async result", "foo"); |
| 62 | +Promise.try((foo, bar) => "Async result", "foo"); |
| 63 | +Promise.try((foo, bar) => "Async result", "foo", undefined); |
| 64 | +Promise.try((foo, bar) => "Async result", "foo", 42); |
0 commit comments