I have run into a TS2322 error while passing the method searchForBooks as props to SearchBooks component from the JumboBooks component:
JumboBooks.tsx (Parent)
import { RouteComponentProps } from 'react-router';
...
export class JumboBooks extends React.Component<RouteComponentProps<{}>, {}> {
...
searchForBooks(searchFilters: SearchParameters){...}
...
public render() {
return (
<div>
<SearchBooks searchForBooks={this.searchForBooks} />
...
}
SearchBooks.tsx
import { RouteComponentProps } from 'react-router';
...
interface IBookSearchProps {
searchForBooks:(filters: SearchParameters)=> void;
}
export class SearchBooks extends React.Component<IBookSearchProps & RouteComponentProps<{}>, {}> {
isearchForBooks() {
var filters: SearchParameters = {
// fill up parameters based on ref values
};
this.props.searchForBooks(filters);
}
...
}
export interface SearchParameters
{
...
}
Error:
Error: TS2322: Type '{ searchForBooks: (searchFilters: SearchParameters) => void; }' is not assignable to type 'IntrinsicAttributes & IntrinsicClassAttributes & Readonly<{ children?: ReactNode; }>...'. Type '{ searchForBooks: (searchFilters: SearchParameters) => void; }' is not assignable to type 'Readonly>'. Property 'match' is missing in type '{ searchForBooks: (searchFilters: SearchParameters) => void; }'.
RouteComponentPropsis adding a necessarymatchprop to yourSearchBookscomponent, but it's not being provided. Does that come from a HOC later on? - Ross AllenSearchBookslike this:<SearchBooks searchForBooks={this.searchForBooks} />, it's not getting thematchprop that you said it needed when you did& RouteComponentProps<{}>. Where does thatmatchprop come from? Is this component wrapped in a higher-order component? - Ross Allen<Route component={...} />? Is that yourJumboBookscomponent? - Ross Allen