-
Notifications
You must be signed in to change notification settings - Fork 12.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(60223): add Promise.try() to ESNext lib (#60232)
- Loading branch information
Showing
79 changed files
with
1,525 additions
and
740 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
interface PromiseConstructor { | ||
/** | ||
* Takes a callback of any kind (returns or throws, synchronously or asynchronously) and wraps its result | ||
* in a Promise. | ||
* | ||
* @param callbackFn A function that is called synchronously. It can do anything: either return | ||
* a value, throw an error, or return a promise. | ||
* @param args Additional arguments, that will be passed to the callback. | ||
* | ||
* @returns A Promise that is: | ||
* - Already fulfilled, if the callback synchronously returns a value. | ||
* - Already rejected, if the callback synchronously throws an error. | ||
* - Asynchronously fulfilled or rejected, if the callback returns a promise. | ||
*/ | ||
try<T, U extends unknown[]>(callbackFn: (...args: U) => T | PromiseLike<T>, ...args: U): Promise<Awaited<T>>; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,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); |
Oops, something went wrong.