Rick Rick - 4 months ago 33
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

typings
attribute in
package.json
and
"declaration": true
in my
tsconfig.json
.

While building the NPM module, I needed the following
.d.ts
files, which I downloaded via the
typings
tool:


  • 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
tsconfig.json
.

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?

Answer

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.

More

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