Rick Rick - 6 months ago 52
Node.js Question

How to manage external .d.ts dependencies while publishing an NPM module?

I am publishing a module to the NPM registry.

It was built with TypeScript (using a

attribute in
"declaration": true
in my

While building the NPM module, I needed the following
files, which I downloaded via the

  • ES6 Promise

  • MQTT.js

When I generate my module and include it in a child project, TypeScript warns me about not using triple slash references in modules. These references were added by TypeScript when I added
"declaration": true
to my

error TS2654:
Exported external package typings file cannot contain
tripleslash references.

If I remove the references, I will get type errors (or duplicate identifier warnings).

What is the correct way to publish an NPM module which has sub-dependencies?


What is the correct way to publish an NPM module which has sub-dependencies

This is changing at the moment. The story for pure ts packages depending on pure ts packages is very clear (more : https://basarat.gitbooks.io/typescript/content/docs/quick/nodejs.html)

However if your package depends upon other .d.ts files for .js projects then I recommend you just mentioning to your users to download the definitions for those .js projects indepdently.


Whats coming: .d.ts NPM packages for .js projects. This is very much in flux and things are changing rapidly in this space.