【发布时间】:2019-04-07 03:06:00
【问题描述】:
我在tsconfig.json 中设置了我的compilerOptions,并使用了以下paths
"paths": {
"react": ["node_modules/@types/react"],
"@types/react": ["node_modules/@types/react"]
}
然而,我可以看到 @types/react-router 正在使用它自己的 @types/react 版本,这会导致编译错误,例如:
ERROR in /path/to/node_modules/@types/react-router/node_modules/@types/react/index.d.ts
ERROR in /path/to/node_modules/@types/react-router/node_modules/@types/react/index.d.ts(2297,27)
TS1005: ';' expected.
如何强制所有模块使用我想要包含的 @types 版本?
【问题讨论】:
-
您不应该像这样安装额外的
@types/react副本,因为最新版本的@types/react-router依赖于允许任何版本的@types/react。你用什么工具来安装包? (npm、yarn 还是其他?)请将您的package.json文件添加到问题中,以便我可以尝试重现问题。
标签: javascript reactjs typescript types