小编Sai*_*Sai的帖子

类型 {} 上不存在属性 ID

  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”}。

因此,这段代码可以工作,但会抛出打字稿错误。

请帮助我如何修复上述打字稿错误。

typescript react-router

2
推荐指数
1
解决办法
8003
查看次数

标签 统计

react-router ×1

typescript ×1