const state = history.location.state;
const id = state?.id;
Following is the typescript error:
Property 'id' does not exist on type '{}'. TS2339
I am getting the id value from history.location.state i.e from react-router I am sending the id prop as state to history.push("pathname",{id:"some value"}.
So,for this code is working but it throws with a typescript error.
Please help me how to fix the above typescript error.
It seems like the TypeScript compiler is not aware of the correct type for
history.location.state. You could try installing types for React:Alternatively, to just get around the error you could force
stateto typeany: