buildLibraryTypes
Emits the declarations with tsc --project ./tsconfig.types.json, then copies each one into dist/lib twice: as a .d.cts whose relative imports name .cjs files and whose bare type imports carry resolution-mode: import, and as a .d.mts whose relative imports name .mjs files.
The library’s root declaration (library.ts where the package has one, otherwise the generated index.ts) carries every lib and types reference the package needs. Every other declaration references a library-references declaration beside it by path, never the root: the root barrel re-exports every module, so referencing it made each subpath load the whole package, and a consumer type-checking with skipLibCheck: false then needed every optional peer installed.
library-references carries only the libs that describe the language (es2022, esnext.disposable), which no consumer conflicts with. The ones that describe a host (dom, dom.iterable, webworker) and types="node" go only into the declarations that name one of their globals, found by resolving every name in the emitted declarations with the type checker. Otherwise a browser consumer of a pure subpath got all of @types/node, and its setTimeout returned NodeJS.Timeout.
Import:
import { buildLibraryTypes } from '@mnaoumov/typescript-dev-toolkit/library-build';Signature:
function buildLibraryTypes(): Promise<void>Returns: Promise<void> — A Promise that resolves when the declarations have been written.
Links to this page: