https://www.typescriptlang.org/docs/handbook/declaration-merging.html
The above link provides information on declaration merging with interfaces. I'd like to be able to do that with an interface that's got a generic component. I'm currently using Typescript 3.0.3.
This does what I want, but I don't understand why I can't do the same thing with declaration merging.
interface MyRouteComponentProps<P, C extends StaticContext = StaticContext> extends RouteComponentProps<P, C> {
loadCandidateFromQueryParam: (candidateId: number) => void
}
class CandidateDetailContainer extends React.Component<MyRouteComponentProps<RouteMatchProps>, {}> {
public componentWillMount() {
this.props.loadCandidateFromQueryParam(Number(this.props.match.params.candidateId));
}
Why doesn't this work?
interface RouteComponentProps<P, C extends StaticContext = StaticContext> {
loadCandidateFromQueryParam: (candidateId: number) => void
}
class CandidateDetailContainer extends React.Component<RouteComponentProps<RouteMatchProps>, {}> {
It seems to completely override the entire definition for RouteComponentProps instead of merging them. I get errors related to P and C never being used (if the definitions were merged then I would expect those errors to go away because they're used in the primary definition). And then I get an error about "match" field not being there. Again, another field that was present in the original definition.
For reference here's the original definition that I'm trying to merge with.
export interface RouteComponentProps<P, C extends StaticContext = StaticContext> {
history: H.History;
location: H.Location;
match: match<P>;
staticContext: C | undefined;
}