Unwrapping the Promises

Example of Awaited use

Seventh challenge is Awaited

Like await in JavaScript, it unwraps Promise and gets the value in the same way.

Sometimes it’s useful to get the value even if it’s double wrapped with Promise so this is also possible.

Unboxing values from types

Type inference in conditional types is defined in TypeScript as following:

Within the extends clause of a conditional type, it is now possible to have infer declarations that introduce a type variable to be inferred. Such inferred type variables may be referenced in the true branch of the conditional type

Example of type inference in conditional types

As we want to unbox double or maybe thrice wrapped Promise we need Recursive Conditional Types:

Example of recursive conditional types

It’s available since TypeScript 4.1 and allows us to do so with Promise too:

Solution

This is it ⭐️

Don’t forget to check the solution on Playground 🚀

typescripteasy

Let's chat and have fun 🧑‍💻👩‍💻

No more often than once a week I write 📄 about TypeScript 💪, video playback 📺 and frontend related topics. You can unsubscribe in any time ↘️