Reactjs 无法使用命名空间';RouteComponentProps';作为一种类型
当我使用typescript时,定义一个扩展RouteComponentProp的接口 我遇到了一些问题: vscode错误:[ts]不能将命名空间“RouteComponents道具”用作类型 控制台错误:无法将命名空间“RouteComponentProps”用作类型Reactjs 无法使用命名空间';RouteComponentProps';作为一种类型,reactjs,typescript,Reactjs,Typescript,当我使用typescript时,定义一个扩展RouteComponentProp的接口 我遇到了一些问题: vscode错误:[ts]不能将命名空间“RouteComponents道具”用作类型 控制台错误:无法将命名空间“RouteComponentProps”用作类型 index.tsx 外部S.d.ts 有人能给点建议吗?谢谢使用react路由器而不是react路由器dom import { RouteComponentProps } from 'react-router' 谢
- index.tsx
- 外部S.d.ts
有人能给点建议吗?谢谢使用
react路由器
而不是react路由器dom
import { RouteComponentProps } from 'react-router'
谢谢,我工作!但是,现在有两行代码,它能更简单吗?从'react router'导入{withRouter,RouteComponentProps}从'react router dom'导入{Link}
Link
不适用于react router
;您需要使用这两个导入,或者您可以创建一个文件来导出所有需要的导入,并在其他文件中使用一个导入,例如,将{RouteComponentProps,Link}
从文件名导出为api
,然后您可以将这两个文件用作从api导入{RouteComponentProps,Link}
"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'
import { RouteComponentProps } from 'react-router'