Generics with Multiple Type Parameters
Here we have the PromiseFunc
that you may recognize from previous exercises:
type PromiseFunc = (input: any) => Promise<any>;
Currently PromiseFunc
takes in a single input as the parameter, which is typed as any
. Additionally, it returns a Promise<any>
.
However, this isn't ide
Transcript
00:00 In this exercise, we're declaring a PromiseFunc type. And PromiseFunc is kind of like a reusable type that we've used in a bunch of different places in this imaginary application. But we want to modify it to make it a generic type. That's because currently PromiseFunc just takes in a single input as the parameter, and this is currently typed as any.
00:19 And then it returns PromiseAny here, okay? And so this isn't great, because we want to be able to say, okay, our first example is a PromiseFunc that takes in first argument of string and returns a string. And we're expecting example one to be of that type, but it's not. And we're getting an error here saying,
00:38 type PromiseFunc is not generic. Ha, interesting. Your job is to try to work out how to make PromiseFunc work as a generic type. Good luck.