Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 common, one user-facing and a sample. Sample depends on user-facing, while that one depends on common.

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

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

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

like image 244
Ritave Avatar asked Oct 22 '25 03:10

Ritave


1 Answers

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.

like image 196
bryanmac Avatar answered Oct 23 '25 20:10

bryanmac



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!