1 00:00:00,150 --> 00:00:01,980 - Now, when we talked about asynchronous functions, 2 00:00:01,980 --> 00:00:04,020 we talked about how you can use Promises, 3 00:00:04,020 --> 00:00:05,340 and this is just a promise 4 00:00:05,340 --> 00:00:07,440 that has a return value of a string. 5 00:00:07,440 --> 00:00:09,720 But oftentimes, when you're dealing with Promises, 6 00:00:09,720 --> 00:00:10,980 you may want to get the type 7 00:00:10,980 --> 00:00:12,570 of whatever the generic is inside of it, 8 00:00:12,570 --> 00:00:14,520 the thing the Promise is returning. 9 00:00:14,520 --> 00:00:16,020 And so far there's no way to do that, 10 00:00:16,020 --> 00:00:17,460 but there is the Awaited type 11 00:00:17,460 --> 00:00:20,370 built into TypeScript that makes this incredibly easy. 12 00:00:20,370 --> 00:00:22,200 So we can create a type that's going to be the value 13 00:00:22,200 --> 00:00:24,900 of our Async function or our Async type here, 14 00:00:24,900 --> 00:00:28,200 and all we need to do is wrap this in our Awaited type. 15 00:00:28,200 --> 00:00:31,110 This Awaited type takes one single type as it's generic, 16 00:00:31,110 --> 00:00:33,390 and all it does is it just removes the Promises from it. 17 00:00:33,390 --> 00:00:35,640 Now you can see here, our value is string. 18 00:00:35,640 --> 00:00:37,290 And even if we have nested Promises, 19 00:00:37,290 --> 00:00:39,780 so if we have a Promise that returns another Promise, 20 00:00:39,780 --> 00:00:42,090 you can see it removes all of the Promise-related stuff 21 00:00:42,090 --> 00:00:43,830 and just gives me the thing that we care about, 22 00:00:43,830 --> 00:00:45,690 which in our case is the string. 23 00:00:45,690 --> 00:00:48,720 This is something very common to use inside of functions. 24 00:00:48,720 --> 00:00:52,470 So for example, if we have an asynchronous function here 25 00:00:52,470 --> 00:00:53,643 that does something, 26 00:00:55,530 --> 00:00:58,620 and we'll just say like return number three here, 27 00:00:58,620 --> 00:01:00,090 what I can do is, by default, 28 00:01:00,090 --> 00:01:02,190 this returns a Promise, which is a number, 29 00:01:02,190 --> 00:01:03,600 because it's an asynchronous function, 30 00:01:03,600 --> 00:01:05,010 even though there's no asynchronous code in there, 31 00:01:05,010 --> 00:01:06,210 just imagine there is. 32 00:01:06,210 --> 00:01:08,310 What I can do is I can say Await, 33 00:01:08,310 --> 00:01:13,140 I want to get to the ReturnType of the typeof this function. 34 00:01:13,140 --> 00:01:15,030 This is very common code that you're gonna see 35 00:01:15,030 --> 00:01:16,470 when dealing with asynchronous function. 36 00:01:16,470 --> 00:01:17,745 As you can see, 37 00:01:17,745 --> 00:01:19,290 this gives me that number value that I care about. 38 00:01:19,290 --> 00:01:21,720 And what it's doing is it's taking an existing function, 39 00:01:21,720 --> 00:01:22,800 figuring out the return type. 40 00:01:22,800 --> 00:01:25,530 And since this return type is essentially a Promise, 41 00:01:25,530 --> 00:01:26,760 I need to wrap this in Awaited 42 00:01:26,760 --> 00:01:27,990 to make sure I get the actual value 43 00:01:27,990 --> 00:01:29,790 of what that Promise is going to be.