【发布时间】:2020-11-16 18:37:36
【问题描述】:
如果我检查历史对象,那么我的代码没有错误:
const handleClick = () => {
if (history) {
history.push('/');
}
};
我认为这将是相同的,但它会产生一个 TypeScript 错误:
const handleClick = () => {
// if (history) {
history?.push('/');
// }
};
错误 TS2339: 属性 'push' 不存在于类型 '"" |历史'。 类型 '""' 上不存在属性 'push'。
27 历史?.push('/');
它们实际上不是一回事吗?
我要导入的历史是这样的:
import { createBrowserHistory } from 'history';
export default process.env.BROWSER && createBrowserHistory();
【问题讨论】:
标签: typescript