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

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

Our application has a WebSocket class that is already defined in lib.d.ts We run our application under Node.js, and not in a web browser, so we really do not need all the definitions from lib.d.ts Instead, lib.core.d.ts would be enough for us (and, of course, it would resolve the WebSocket conflict).

Can I tell the TypeScript compiler which global type definition file to use?

+7
javascript typescript
source share
2 answers

Use the --noLib compiler option to exclude lib.d.ts , and then add the link to lib.core.d.ts to the source files.

The equivalent for tsconfig.json would be "noLib": true .

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

+6
source share

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

Hope this helps.

0
source share

All Articles