Ritave Ritave - 5 months ago 24
TypeScript Question

What is the proper way to include Typescript typings for js packages which will be published to npm?

I have 3 NodeJS packages, 2 of which will be published to npm later on and are in javascript, I want for them to have typings included with them. How do I do that properly?

I have one library

, one
and a sample. Sample depends on
, while that one depends on

I've created typings file for each .js file in each package, I included
directive in
for each package specifying the main typing file.

But when I try to compile my sample
properly finds the typings for
but then complains that it can't find further typings inside the files of
which are trying to import

How can I run my sample locally without publishing the typings to registry beforehand?


You shouldn't have to publish things to the typings registry for libraries that you create. They can carry their own typings. The typings registry is for creating typings for libraries that others created.

You want to include a typings element in the package.json

Example here

"typings": "./yourentry.d.ts",

And then have the build produce the typing .d.ts files

In your tsconfig:

{ "compilerOptions": {, "declaration": true,

Doing that will allow tsc and vscode to find it and when consumers do an npm install, it will just work for compile time and intellisense.