Extract the Result of an Async Function
This exercise is an amalgamation of several things you've learned so far.
We have a function called getServerSideProps
that doesn't have an explicit return type set:
const getServerSideProps = async () => { const data = await fetch("https://jsonplaceholder.typicode.com/todos/1") const
Transcript
0:00 We've got a bit of an interesting problem here. We have a getServerSideProps function, which we're not adding a return type to. We're just letting it infer the thing that's being passed down, so it's returning a promise with props, JSON, title.
0:14 We want to create a type helper here, which helps us go into typeof getServerSideProps and extract out whatever is put into props here. This means that whenever we have a getServerSideProps function, we'll be able to grab out the props from anything that we pass in.
0:32 So your job here is we're going to need a conditional check. We're going to need an infer in here, and we're going to need to make sure that we grab out the right thing and return it. Otherwise, we're going to return never. There's nothing particularly new in here. This is just an amalgamation of a few things that you've learned already.