reactjs - react-router-dom 和 Typescript:需要类型注释。ts(2742)
问题描述
我正在尝试使用 react-router-dom 路由类组件。当我withRouter
在我的组件上使用时,我收到此错误:
如果没有对 的引用,则无法命名推断的“默认”类型
'react-transition-group/node_modules/@types/react'
。这可能是不可移植的。类型注释是必要的。ts(2742)
示例代码:
/* eslint-disable react/prefer-stateless-function */
import React from "react";
import { RouteComponentProps, withRouter } from "react-router-dom";
type Params = {
value: string;
};
type Props = RouteComponentProps<Params>;
class ClassComponent extends React.Component<Props> {
render() {
const { match } = this.props;
return <span>Value: {match.params.value}</span>;
}
}
export default withRouter(ClassComponent);
我需要注释什么以及如何注释?
解决方案
我通过删除 node_modules 文件夹并重新下载所有依赖项来解决此问题。
推荐阅读
- html - 根据不同的英雄超能力为表格的行添加特定的颜色
- angular7 - 如何使用 POST 请求将 3 个参数传递给后端?
- php - 如何在php中获取sql查询
- c++ - 当 n 的默认值是字符串的长度时,如何反转字符串中的 n 个字符?
- ios - UITableview单元格中的UITableview动态高度调整
- c++17 - Tick Traits 库,如何将 Tick 类声明为朋友
- python - 此平台不支持 mysql 轮子
- javascript - Solidity 函数将空数组返回给 web3.js
- python - 如何使用 python 将我的字节数据转换为整数?
- javascript - 如何应用从控制器或 javascript 获取值的输入掩码