TypeScript中import路径映射处理过的模块提示无法找到

举个例子:

import { RouterProps } from 'react-router'

上面的 react-router 实际指向了本地的 src/components/react-router,并且在 src/components/react-router/index.tsx 文件有:

export interface RouterProps {
  action?: Action
  children?: React.ReactNode
  location: Location
  navigator: Navigator
  static?: boolean
}

此时TS会找不到 react-router 模块,这我是能理解的,但有什么解决办法吗?

我通过tsconfig中配置paths参数也没用啊!

{
    "baseUrl": ".",
    "paths": {
      "react-router": ["src/components/react-router"]
    }
}

难道要手写一个声明文件,比如这样?

declare module 'react-router' {
     export {...}
}
阅读 2.1k
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进