Publishing declaration files
suggest changeLibraries written in TypeScript can emit declarations alongside JavaScript:
{
"compilerOptions": {
"declaration": true,
"declarationMap": true,
"emitDeclarationOnly": false,
"outDir": "dist"
}
}
Point package.json at the public entry points and include generated declarations in the published package. This example describes a package that publishes one ESM entry point:
{
"type": "module",
"types": "./dist/index.d.ts",
"exports": {
".": {
"types": "./dist/index.d.ts",
"import": "./dist/index.js"
}
},
"files": ["dist"]
}
Export only supported public types. Avoid exposing internal paths that consumers cannot import at runtime. Packages that publish both ESM and CommonJS need separate runtime outputs and matching declaration entry points; do not point both conditions at incompatible files. If public declarations reference types from another package, consumers must be able to install and resolve that dependency.
Found a mistake? Have a question or improvement idea?
Let me know.
Table Of Contents