【发布时间】:2019-04-29 16:46:12
【问题描述】:
我是打字稿的新手,很难弄清楚如何在窗口对象上定义browserHistory。我正在使用来自 ReactTraining 的 history 包。
在我的app.jsx 我有:
import { createBrowserHistory } from 'history';
const history = createBrowserHistory({
basename: basePath,
});
window.browserHistory = history;
然后在我的modules.d.ts 中,我的代码不起作用:
import { History } from '@types/history';
interface Window { browserHistory: History; }
任何地方都是我正在使用的应用程序window.browserHistory 我收到错误:
TS2339: Property 'browserHistory' does not exist on type 'Window'.
我可以让这个错误消失,但是用any 替换History 但这似乎是一种不正确的方法。 npm 包@types/history 好像没有明确的例子。
【问题讨论】:
标签: reactjs typescript react-router