Type Transformations Workshop (4 exercises)
Problem

Extract The Awaited Result of a Promise

In this exercise we've got a function getUser, that returns a promise containing the strings id, name, and email.

When hovering over getUser we can see that the strings are wrapped in the Promise type:

To get the return type from getUser, we could try using the ReturnType utility type as seen in the previous exercises:

However, in this case the return value is still wrapped in the Promise type:

Challenge

Your job is to extract the awaited result of the promise using a utility type that we haven’t used yet.

ReturnValue needs to pass the tests by being equal to { id: string; name: string; email: string }:

If you need a refresher on the Promise type, check out Typing Promises and Async Requests from my Beginner’s TypeScript Tutorial.

Transcript

[0:00] In this exercise, we've got a function that returns a Promise with ID, name, and string inside of it. We can see here that it's wrapped in this promise type here, which we covered in the beginners course. What you end up with is we're trying to extract the return value, but the return value is still wrapped in this promise type.
[0:19] We don't return type, but what we're getting back is a promise. Your job is to try and see if we can extract the awaited result of that Promise. This is going to need another utility type as one. What we want is for return value to be equal to ID string, name string, and email string.