代码之家  ›  专栏  ›  技术社区  ›  Kousha

typescript在react中使用了不同版本的@types

  •  2
  • Kousha  · 技术社区  · 6 年前

    我已经把我的 compilerOptions 在里面 tsconfig.json 有以下几点 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版本?

    1 回复  |  直到 6 年前
        1
  •  0
  •   Yasin Tazeoglu    6 年前
    npm install @types/yourModule --save-dev
    

    你能试试吗

    不要触摸tsconfig.json文件