How would you configure tsconfig.json differently for a library meant to be published to npm versus an internal application, particularly regarding 'declaration' and 'sourceMap'?
Short answer
A published library should set 'declaration': true (so consumers get type information) and typically 'declarationMap': true plus 'sourceMap': true (so consumers' editors can jump to real source and debug through it); an internal application typically doesn't need 'declaration'…
Advertisement
AModel answer
A published library should set 'declaration': true (so consumers get type information) and typically 'declarationMap': true plus 'sourceMap': true (so consumers' editors can jump to real source and debug through it); an internal application typically doesn't need 'declaration' output at all, since nothing downstream consumes it as a typed dependency — reducing unnecessary build output.
// Library tsconfig.json
{
"compilerOptions": {
"declaration": true,
"declarationMap": true,
"sourceMap": true,
"outDir": "dist"
}
}
// Internal app tsconfig.json typically omits 'declaration' entirelyReal-world example
Configuring a monorepo where shared internal packages generate full declaration output for consumption by other packages, while the top-level app doesn't.
Likely follow-ups
- Why would generating unnecessary .d.ts files for a non-published internal application be considered pure build overhead?
Related topics