当我使用打字稿时,定义一个扩展RouteComponentProp的接口
我遇到了一些问题:
vscode错误:[ts]不能将命名空间“ RouteComponentProps”采用类型
控制台错误:不能使用名称空间“ RouteComponentProps”作为类型。
import React from 'react';
import Styles from './header.less';
import { Link, withRouter, RouteComponentProps } from 'react-router-dom'
interface Props extends RouteComponentProps<any>{} //it can not be work well
class Header extends React.Component<Props, States> {.....}
"compilerOptions": {
"outDir": "./dist/",
"sourceMap": true,
"jsx": "react",
"esModuleInterop": true,
"allowSyntheticDefaultImports":true,
"lib": ["es6", "dom"],
"strictNullChecks": true,
"target": "es2016",
"module": "ESNext", // !important!
"moduleResolution": "node",
"strict": true,
"typeRoots": [
"node_modules/@types"
],
},
"include": [
"./src/**/*",
"./externals.d.ts"
],
"exclude": [ "node_modules" ]
}
declare module '*.less'
declare module 'react-router-dom'
有人可以提出建议吗?谢谢
答案 0 :(得分:1)
使用react-router
代替react-router-dom
import { RouteComponentProps } from 'react-router'