我刚开始在我的React项目中添加TypeScript,我无法弄清楚这个错误: import {Link} from 'react-router';Module '"/Users/.../node_modules/@types/react-router/index"' has no exported member 'Link'. Link组件存在于react-rou
import {Link} from 'react-router'; Module '"/Users/.../node_modules/@types/react-router/index"' has no exported member 'Link'.
Link组件存在于react-router中(代码正在运行),但TypeScript无法识别它.我添加了@ types / react-router,似乎没有实现Link.有任何想法吗 ?
从我的package.json中提取:
"@types/react": "^15.0.25", "@types/react-dom": "^15.5.0", "@types/react-router": "^4.0.11", "@types/reactstrap": "^4.3.4", ... "react": "^15.4.2", "react-dom": "^15.4.2", "react-router": "^3.0.2", "reactstrap": "^4.2.0" ... "typescript": "^2.3.3",你有反应路由器版本3,但版本4的@types包.refer-router版本4将很多库移动到react-router-dom包中,这就是为什么他们的类型不在@ types / react-router v4包.
您应该删除不正确的类型包:
npm un @types/react-router
然后安装正确的类型:
npm i --save-dev @types/react-router@3