Reputation: 1483
Typings are one the best features of Typescript and I find it very useful, to adopt it all over the javascript project, however the usage and best practices are not documented very efficient that causes a lot of confusion for the developers.
For example my npm package named my-awesome-pkg
and for this package we are interested to have @typings, that users are able to install it using npm npm install @types/my-awesome-pkg
I know how to use include
or files
in tsconfig.json
to include and use the @typings in your project :
"include": [ "< path to your typing file>" ]
But that is not my what I am looking for, I am interested to know, how to create installable @typings for my project, so users don't get frustrated looking for the typings of my npm package, as assume there is an standard practice for doing it.
Thanks,
Upvotes: 1
Views: 2102
Reputation: 803
So in case that your project is written in TypeScript all you have to do is to set the following flags in your project's tsconfig.json
:
"declaration": true,
"declarationDir": './anyFolderYouLike'
This will generate types for your TypeScript project when tsc
is run. For further information on how to configure the tsc
see here.
Many people host their types on DefinitelyTyped. That way one should be able to install the types the way you wish to.
I am seeing more and more folks delivering their types with their own package though. This way there is no need to install them separately. If you want to do it that way you should specify the types location in the package.json
, i.e.:
"types": "./lib/index.d.ts"
For further overall information on publishing please refer to the TypeScript publishing documentation.
Upvotes: 2