Skip to content

Commit dbb3235

Browse files
committed
fix(60223): add Promise.try() to ES2024 lib
1 parent 40caf34 commit dbb3235

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

src/lib/es2024.promise.d.ts

+14
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,18 @@ interface PromiseConstructor {
1414
* ```
1515
*/
1616
withResolvers<T>(): PromiseWithResolvers<T>;
17+
18+
/**
19+
* Takes a callback of any kind (returns or throws, synchronously or asynchronously) and wraps its result
20+
* in a Promise.
21+
*
22+
* @param callbackFn A function that is called synchronously with no arguments. It can do anything: either return
23+
* a value, throw an error, or return a promise.
24+
*
25+
* @returns A Promise that is:
26+
* - Already fulfilled, if callbackFn synchronously returns a value.
27+
* - Already rejected, if callbackFn synchronously throws an error.
28+
* - Asynchronously fulfilled or rejected, if callbackFn returns a promise.
29+
*/
30+
try<T>(callbackFn: () => T | Promise<T>): Promise<T>;
1731
}

0 commit comments

Comments
 (0)