Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/powershell/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Reactjs 无法使用命名空间';RouteComponentProps';作为一种类型_Reactjs_Typescript - Fatal编程技术网

Reactjs 无法使用命名空间';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' 谢

当我使用typescript时,定义一个扩展RouteComponentProp的接口

我遇到了一些问题:

vscode错误:[ts]不能将命名空间“RouteComponents道具”用作类型

控制台错误:无法将命名空间“RouteComponentProps”用作类型

  • 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'