Your tsconfig.json
has a small error where you set "declarations": true
instead of "declaration": true
. Additionally, the exclude
field should be outside of the compilerOptions
block. You are also referencing types from a non-existent file called index.d.ts
. Helpful links for configuring TypeScript:
Compiler Options,
tsconfig.json Handbook.
To generate the module, follow these steps:
Write code for all utilities to be exposed in your module, entities that should be 'importable'.
Create a file in src (assuming src is your rootDir
) named index.tsx or another choice. Export the entities to expose in this file.
In package.json, add
"main": "<outDir>/index.js"
and "typings": <outDir>/index.d.ts
. Replace <outDir>
with your output directory from tsconfig
. The main
field specifies where importing apps should reference. For example, if an app executes import {abc} from 'swagger-client'
,
main
indicates to look for abc
in the "<outDir>/index.js"
file.
The typings
field in TypeScript tells where to find types corresponding to abc
.
Note the extensions mentioned in main
and typings
fields; they are not ts files. It's recommended not to publish .ts files to npm but to github, and publish generated .js, .d.ts files to npm. This practice ensures usability in js and ts projects.