Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to exclude *.d.ts file for TypeScript compiler?

I use a npm module [email protected] which has some mistakes in its index.d.ts file.

I want to ignore this file (node_modules/web3/index.d.ts) for TS compiler and I want to use my own types file.

But tsc still use this wrong file and can't compile my project.

Here is my tsconfig.json:

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

  "exclude": ["node_modules/web3/index.d.ts"]
}

If I manually remove node_modules/web3/index.d.ts, tsc compiles my project.

How to exclude this file for tsc?

I've created a repo with minimum code to reproduce this problem: https://github.com/serge-nikitin/q1

like image 411
Serge Nikitin Avatar asked Oct 24 '17 15:10

Serge Nikitin


People also ask

How do I ignore files in TypeScript?

Use // @ts-ignore to ignore the type checking errors on the next line in a TypeScript file. If you use a linter, you might have to add a comment to also suppress linting errors when using ts-ignore - // eslint-disable-next-line @typescript-eslint/ban-ts-comment .

What is the use of D ts file in TypeScript?

d. ts is the type definition files that allow to use existing JavaScript code in TypeScript. declare function sum(a: number, b: number): number; From now on, we can use the function in TypeScript without any compile errors.

What is exclude in Tsconfig?

Use the exclude option in your tsconfig. json file to exclude a folder from compilation in TypeScript. The exclude option changes what the include setting finds and defaults to node_modules and bower_components .


1 Answers

Try add this options to tsconfig.json to ignore lib declaration files checking while compiling.

{
  "compilerOptions": {
    "skipLibCheck": true
  },
}
like image 56
t7yang Avatar answered Sep 22 '22 15:09

t7yang