I encountered a type declaration in the library react-router that is causing me a lot of trouble to understand:
export interface RouteComponentProps<
Params extends { [K in keyof Params]?: string } = {},
C extends StaticContext = StaticContext,
S = H.LocationState
> {
...
}
The first line of the generics is the hardest for me. And I would love some help with this...
Params extends { [K in keyof Params]?: string } = {}
As far as I understand it, we are taking some interface called Params as an argument and then we make every element in that interface optional. So, we are manipulating the passed in interface.
I am also having a lot of trouble understanding the equal sign = {}. What does it mean to extend an interface and setting it equal to something? Thanks!
{ [K in keyof Params]?: string }. The= {}is just providing a default value for that type parameter- so if you do not pass any type param, it'll default to{}.[K in keyof Params]?- ? is this so the compiler wont complain whenParamsis empty?