【发布时间】:2019-06-27 05:16:53
【问题描述】:
我在我的 React 应用程序中导入 @types/history 并使用它提供的 createBrowserHistory() 函数。
我收到一个 tslint 错误提示,
ERROR in C:/Users/eshan/my-website/src/App.tsx
ERROR in C:/Users/eshan/my-website/src/App.tsx(13,11):
typedef: expected variable-declaration: 'history' to have a typedef
我确实环顾了一下,但所有减轻这种情况的尝试似乎都是为了通过执行/* tslint:disable */ 来删除 tslint 规则。我想添加类型支持,然后修复它。
import * as React from 'react';
import { Router, Route, Switch } from 'react-router-dom';
import { createBrowserHistory } from 'history';
import './App.css';
class App extends React.Component {
public render(): JSX.Element {
const history = createBrowserHistory();
return (
<div className='App'>
<Router history={history}>
<Switch>
<Route exact path='/' component={Landing}/>
<Route exact path='/Home' component={Home}/>
</Switch>
</Router>
</div>
);
}
}
export default App;
【问题讨论】:
标签: typescript tslint