@@ -23,12 +23,20 @@ export const installPolyfills = (): void => {
2323} ;
2424
2525const installPromisePolyfills = ( ) => {
26+ const PromiseStatic = Promise as PromiseConstructor & {
27+ withResolvers ?: < T > ( ) => PromiseWithResolvers < T > ;
28+ try ?: (
29+ func : ( ...args : ReadonlyArray < unknown > ) => unknown ,
30+ ...args : ReadonlyArray < unknown >
31+ ) => Promise < unknown > ;
32+ } ;
33+
2634 // @see https://github.com/facebook/hermes/pull/1452
27- if ( typeof Promise . withResolvers !== "function" ) {
28- // @ts -expect-error This is OK.
29- Promise . withResolvers = ( ) => {
30- let resolve , reject ;
31- const promise = new Promise ( ( res , rej ) => {
35+ if ( typeof PromiseStatic . withResolvers !== "function" ) {
36+ PromiseStatic . withResolvers = < T > ( ) => {
37+ let resolve : ( value : T | PromiseLike < T > ) => void = ( ) => { } ;
38+ let reject : ( reason ?: unknown ) => void = ( ) => { } ;
39+ const promise = new Promise < T > ( ( res , rej ) => {
3240 resolve = res ;
3341 reject = rej ;
3442 } ) ;
@@ -37,9 +45,8 @@ const installPromisePolyfills = () => {
3745 }
3846
3947 // @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/try
40- if ( typeof Promise . try !== "function" ) {
41- // @ts -expect-error This is OK.
42- Promise . try = (
48+ if ( typeof PromiseStatic . try !== "function" ) {
49+ PromiseStatic . try = (
4350 func : ( ...args : ReadonlyArray < unknown > ) => unknown ,
4451 ...args : ReadonlyArray < unknown >
4552 ) : Promise < unknown > =>
0 commit comments