How do 'declaration' and 'declarationMap' compiler options in tsconfig.json affect a published npm package?
Short answer
Setting "declaration": true generates a corresponding .d.ts file for every compiled .ts file automatically, giving consumers of your published package full type information without hand-writing declarations.
Advertisement
AModel answer
Setting "declaration": true generates a corresponding .d.ts file for every compiled .ts file automatically, giving consumers of your published package full type information without hand-writing declarations. "declarationMap": true additionally generates source maps for those .d.ts files, letting editors 'Go to Definition' jump straight into your original TypeScript source instead of the generated declaration file.
// tsconfig.json
{
"compilerOptions": {
"declaration": true,
"declarationMap": true,
"outDir": "dist"
}
}Real-world example
Publishing an npm library where consumers get full type support and can jump directly to your original source for definitions.
Likely follow-ups
- Why would you want declarationMap disabled in a final production package release?
Related topics