Use TypeScript lib.core.d.ts instead of lib.d.ts

3.1k views Asked by At

It seems the TypeScript compiler always includes lib.d.ts or lib.es6.d.ts (depending on the compiler target).

In our application we have a WebSocket class that is already defined in lib.d.ts. We're running our application under Node.js and not in a web browser, so we actually don't need all of the definitions from lib.d.ts. Instead lib.core.d.ts would be sufficient for us (and would solve the WebSocket conflict of course).

Is it possible to tell the TypeScript compiler which global type definition file to use?

2

There are 2 answers

0
zlumer On BEST ANSWER

Use --noLib compiler option to exclude lib.d.ts and then add reference to lib.core.d.ts in your source files.

Equivalent for tsconfig.json would be "noLib": true.

If you only need Node.js definitions, you can also use the Definitely Typed one.

0
vlio20 On

Another solution might be to use lib like core-js. which has all the required polyfils for ES6. Note: you will also will need to add the core-js tsd file to your tsds.

Hope it helps.