Make the PromiseValue type handle nested promises#112
Make the PromiseValue type handle nested promises#112sindresorhus merged 9 commits intosindresorhus:masterfrom onichandame:master
PromiseValue type handle nested promises#112Conversation
|
Shouldn't |
So I decided to post the changes first and see how people think about this. |
|
Are you aware that they plan to solve this problem in TypeScript itself? microsoft/TypeScript#27711 (comment) |
|
I doubt it will break in the future, but if so, we could probably find a workaround. |
|
I did look at that issue. The problem is that the official support won't be available before TS 4.0. Before TS people have solved the problem, it is necessary to have this type as a temporary workaround. I do wish to alter the behaviour of |
PromiseValueRecursive typePromiseValue type handle nested promises
As per this discussion, a more realistic use case of unwrapping a type from Promise is when the Promise is resolved to another Promise.
For example,
await Promise.resolve(Promise.resolve(2))is resolved asnumber, notPromise<number>. The current typePromiseValuehowever, does not reflect this behaviour.Thanks to Gerrit0 who shared the trick, I stole his brilliant idea and brought to this package.