- Now, when we talked about asynchronous functions,
we talked about how you can use Promises,
and this is just a promise
that has a return value of a string.
But oftentimes, when you're dealing with Promises,
you may want to get the type
of whatever the generic is inside of it,
the thing the Promise is returning.
And so far there's no way to do that,
but there is the Awaited type
built into TypeScript that makes this incredibly easy.
So we can create a type that's going to be the value
of our Async function or our Async type here,
and all we need to do is wrap this in our Awaited type.
This Awaited type takes one single type as it's generic,
and all it does is it just removes the Promises from it.
Now you can see here, our value is string.
And even if we have nested Promises,
so if we have a Promise that returns another Promise,
you can see it removes all of the Promise-related stuff
and just gives me the thing that we care about,
which in our case is the string.
This is something very common to use inside of functions.
So for example, if we have an asynchronous function here
that does something,
and we'll just say like return number three here,
what I can do is, by default,
this returns a Promise, which is a number,
because it's an asynchronous function,
even though there's no asynchronous code in there,
just imagine there is.
What I can do is I can say Await,
I want to get to the ReturnType of the typeof this function.
This is very common code that you're gonna see
when dealing with asynchronous function.
As you can see,
this gives me that number value that I care about.
And what it's doing is it's taking an existing function,
figuring out the return type.
And since this return type is essentially a Promise,
I need to wrap this in Awaited
to make sure I get the actual value
of what that Promise is going to be.