状态上不存在该属性-将React Router挂钩与TypeScript一起使用

使用react-router-dom挂钩+ TypeScript时遇到一些问题。

尝试访问某些状态属性将给出错误消息,指出该属性不存在

参考:

enter image description here

One of the workarounds that I had to do in order to continue development, was to cast it to any

 const location = useLocation() as any;

如何在不发出警告的情况下将有效接口传递给useLocation泛型,以访问状态属性?

  useDidMount(() => {
    if (location.state?.newTransactions) {
      scroll.scrollToBottom();
    }
  });