- Notifications
You must be signed in to change notification settings - Fork 13.2k
Better typings for Promise.all(), like #31117#33055
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Uh oh!
There was an error while loading. Please reload this page.
Conversation
jablko commented Aug 23, 2019 • edited
Loading Uh oh!
There was an error while loading. Please reload this page.
edited
Uh oh!
There was an error while loading. Please reload this page.
msftclas commented Aug 23, 2019 • edited
Loading Uh oh!
There was an error while loading. Please reload this page.
edited
Uh oh!
There was an error while loading. Please reload this page.
c66f6e0 to 43b4530Compare6dcb395 to 2b698caCompare6798944 to 5ff6760Compared6342df to 22ed2e6Compare54b80d3 to 5b4d5a0Compare2b7d312 to 6a795b1Compare3e30222 to bbdeb4fCompare55fef89 to 22b1502Compare176fe78 to e44e540Comparef855f50 to 4bed207Compare3e6b78f to 171dad8CompareYou can include es2015.promise.d.ts without es2015.iterable.d.ts. It was moved to es2015.promise.d.ts in microsoft#31117
Luxcium commented Mar 24, 2020 • edited
Loading Uh oh!
There was an error while loading. Please reload this page.
edited
Uh oh!
There was an error while loading. Please reload this page.
as in my issue comment in #37526 UpdateMy problem is solved with the nightly version of typescript but I will leave it there in case it can be useful for something or someone
I have placed a copy of this resolved problem in #33055 and in #33707 hoping it can be helpful and not too spammy ... Issue now fixedI have a similar problem and I don't know if I should open a different issue ...
// Promise.all(this.fork) take a T1[] where T1 is a Promise<number>// and return a Promise<T2[]> where T2 is a number// therefore T1 and T2 are not both «T»exportclassMyMaybeList<T=any>{privateconstructor(values: T[]){this.values=values;}privatevalues: T[];// get =======================================================-| fork() |-====publicgetfork(): T[]{returnthis.values!=null ? this.values.slice() : [].slice();}// public =====================================================-| map() |-====publicmap<R=any>(fn: (val: T,index: number,array: T[])=>R): MyMaybeList<R>{returnMyMaybeList.of(...this.values.map(fn));}// static ======================================================-| of() |-====publicstaticof<TVal>(...val: TVal[]): MyMaybeList<TVal>{if(val==null||!val.length)returnnewMyMaybeList<TVal>([]);returnnewMyMaybeList<TVal>([...val]);}// async =====================================================-| will() |-====publicasyncwill/* <R> */()/* : Promise<MyMaybeList<R>> */{// Promise.all(this.fork) take a T1[] where T1 is Promise<number>// and return a Promise<T2[]> where T2 is a number// therefore T1 and T2 are not both «T»console.log(this.fork);constwillThen=Promise.all(this.fork);constthenWill=awaitwillThen;returnMyMaybeList.of(...thenWill);}}constoneToTen=MyMaybeList.of(1,2,3,4,5,6,7,8,9,10);constpowersOneToTen=oneToTen.map(asyncval=>val*val);// "log->" powersOneToTen: MyMaybeList<Promise<number>>console.log(powersOneToTen);// "log->" awaitedList: MyMaybeList<Promise<number>>// instead of a -> MyMaybeList{Promise<number>}// in fact is a -> Promise{MyMaybeList<number>}constawaitedPowersOneToTen=powersOneToTen.will/* <unnknow> */();awaitedPowersOneToTen.then(awaitedList=>console.log(awaitedList));// Promise{<pending>} will resolve into ->console.log(awaitedPowersOneToTen);/* // Promise.all(this.fork) take a T1[] where T1 is Promise<number> // and return a Promise<T2[]> where T2 is a number // therefore T1 and T2 are not both «T» // console.log(this.fork); will display same as console.log(powersOneToTen);// console.log(powersOneToTen); ->// "log->" powersOneToTen: MyMaybeList<Promise<number>>MyMaybeList{ values: [ Promise{1 }, Promise{4 }, Promise{9 }, Promise{16 }, Promise{25 }, Promise{36 }, Promise{49 }, Promise{64 }, Promise{81 }, Promise{100 } ]}// console.log(awaitedPowersOneToTen); ->// "log ->" awaitedPowersOneToTen: Promise<MyMaybeList<Promise<number>>>Promise{<pending>}// Promise{<pending>} will resolve into ->// awaitedPowersOneToTen.then(awaitedList => console.log(awaitedList)); ->// console.log(awaitedList) ->// "log->" awaitedList: MyMaybeList<Promise<number>>// instead of a -> MyMaybeList{Promise<number>}// in fact is a (should be) -> Promise{MyMaybeList<number>}MyMaybeList{ values: [ 1, 4, 9, 16, 25, 36, 49, 64, 81, 100 ]}*/ |
Luxcium commented Mar 27, 2020
Now that #37610 has reverted the
|
jakebailey commented Jan 24, 2022
All of the issues this PR links are closed; I think that this all was handled in 4.5 with I'm going to close this, but am happy to reopen if I'm mistaken. |



Fixes#22469
Fixes#28427
Fixes#31722