如何为TypeScript编译器排除*.d.ts文件?

Ser*_*tin 6 typescript typescript-typings

我使用了一个npm模块web3@1.0.0-beta.24,它在index.d.ts文件中有一些错误.

我想忽略TS编译器的这个文件(node_modules/web3/index.d.ts),我想使用我自己的类型文件.

但是tsc仍然使用这个错误的文件,无法编译我的项目.

这是我的tsconfig.json:

{
  "compilerOptions": {
    "target": "es5",
    "module": "commonjs",
    "strict": true
  },

  "exclude": ["node_modules/web3/index.d.ts"]
}
Run Code Online (Sandbox Code Playgroud)

如果我手动删除node_modules/web3/index.d.ts,tsc编译我的项目.

如何为tsc排除此文件?

我用最少的代码创建了一个repo来重现这个问题:https: //github.com/serge-nikitin/q1

t7y*_*ang 14

尝试将此选项添加到tsconfig.json以忽略编译时检查的lib声明文件.

{
  "compilerOptions": {
    "skipLibCheck": true
  },
}
Run Code Online (Sandbox Code Playgroud)

  • 不,这不是跳过生成 d.ts 文件,而是跳过 d.ts 文件的类型检查。 (3认同)
  • 对于我使用 TypeScript v3.9.9 和 Win10 来说,这不起作用。在构建过程中,我的文件列表中仍然有 d.ts 文件 (2认同)