Is there anyone who can assist me with a Typescript issue I'm currently facing?
Upon running tsc in my project, I encountered the following error:
I am getting the error saying that 'Argument of type '{ pathname: string; item: Item; }' is not assignable to parameter of type 'To'. Object literal may only specify known properties, and 'item' does not exist in type 'PartialPath'.
This error stems from a line of code where I am attempting to utilize the location state in a history.push
.
The relevant code snippet from my project is as follows:
[...]
interface RouterParams {
orderId: string,
}
interface LocationState {
item: Item,
}
interface RowProps extends RouteComponentProps<RouterParams, StaticContext, LocationState> {
item: Item,
};
const Row = ({ row, history, match }: RowProps) => (
<button
onClick={
const orderId = match.params.orderId;
history.push({
pathname: `/orders/${orderId}/items/${row.id}`,
// This is where the error occurs
item: row,
});
}
>
</button>
);
export default withRouter(Row);
The react-router and types versions in my package.json are as follows:
[...]
"dependencies": {
[...]
"react-router": "5.2.0",
"react-router-dom": "^5.2.0",
[...]
"devDependencies": {
"@types/react-router-dom": "^5.1.7",
[...]