【问题标题】:Exclude or Overwrite existing type definition file排除或覆盖现有类型定义文件
【发布时间】:2017-11-21 08:45:27
【问题描述】:

我正在寻找一种方法来用我自己的方法覆盖现有的库定义文件以包含一些修复。目录结构如下:

node_modules/
  preact/
    dist/
      preact.d.ts <-- this file is wrong, I'd like to use my own
types/
  preact.d.ts <-- use this file instead

有没有办法完全覆盖 preact 附带的文件或排除该文件被拾取?现在它到处都显示Duplicate identifier

如果有帮助,这是我的tsconfig.json 文件:

{
    "compilerOptions": {
        "target": "es2017",
        "module": "commonjs",
        "sourceMap": false,
        "lib": [
            "dom",
            "es5",
            "es6",
            "es7"
        ],
        "sourceRoot": "src",
        "outDir": "dist",
        "jsx": "react",
        "jsxFactory": "h",
        "noImplicitAny": true,
        "noImplicitThis": true,
        "noImplicitReturns": true,
        "noUnusedLocals": true,
        "noUnusedParameters": true,
        "strictNullChecks": true,
        "allowSyntheticDefaultImports": true,
        "noEmitOnError": true
    },
    "include": [
        "src/**/*",
        "types/**/*"
    ],
    "exclude": [
        "node_modules/preact/dist/preact.d.ts"
    ],
    "baseUrl": ".",
    "paths": {
        "*": [
            "types/*"
        ]
    }
}

谢谢!

【问题讨论】:

    标签: typescript


    【解决方案1】:

    哎呀!看起来我在这里找到了答案:Exclude/overwrite npm-provided typings

    paths 应该在compilerOptions 之下,而不是顶级。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2019-12-27
      • 2017-05-28
      • 2018-04-09
      • 1970-01-01
      • 2018-07-21
      • 1970-01-01
      • 2016-02-12
      相关资源
      最近更新 更多