const state = history.location.state;
const id = state?.id;
Run Code Online (Sandbox Code Playgroud)
以下是打字稿错误:
Property 'id' does not exist on type '{}'. TS2339
Run Code Online (Sandbox Code Playgroud)
我从history.location.state获取id值,即从react-router我将id属性作为状态发送到history.push(“pathname”,{id:“some value”}。
因此,这段代码可以工作,但会抛出打字稿错误。
请帮助我如何修复上述打字稿错误。