Example of typescript types package.
To use our types as package we need to compile it to the .d.ts a.k.a declarations and then push it to the registry.
-
Setup
tsconfig.json"declaration": true- activating declarations in our project."emitDeclarationOnly": true- allows to get only typings from our code."declarationDir": "./dist"- directory for declarations output
-
Create
index.tsoutsidesrcfolder.Allows us to export all code from src.
-
Build
tsc
- Add
.tsor.d.tsfiles to thesrcfolder. - Run
buildscript from package.json or via command line with your package manager:
npm run buildyarn buildpnpm build- Inspect compiled types declarations in the
distfolder.
I added files for npm registry. You can safely delete it or replace.
- Login:
npm login- Publish:
npm publish --access publicNOTE: Sometimes you need to provide login token or something similar. Remember to delete it from your project.