Sub topic 12
Generating Declarations in Parallel with Other Tools
This chapter assumes you know basic TypeScript types, can run tsc, and understand that a .d.ts file describes a module's public types without containing its runtime implementation. It also assumes you have seen isolatedDeclarations and explicit annotations in a TypeScript configuration.
Why use another declaration emitter?
TypeScript normally checks a program as a connected graph. It needs information from imported files before it can safely infer the types exported by the current file. This makes declaration generation accurate, but it also limits parallelism.
The isolatedDeclarations option changes the contract. It requires exported declarations to contain enough information for a tool to produce that file's .d.ts output without checking the rest of the program.
A compatible third-party emitter can then process source files independently:
- File A can produce
a.d.tswhile file B producesb.d.ts. - A build tool can distribute files across worker threads or processes.
- Declaration generation can run beside JavaScript bundling.
- A separate
tsc --noEmitprocess can perform full type checking.
This approach trades some inference convenience for build speed and a stricter public API.
The split-build workflow
With isolatedDeclarations, a build can separate checking from emitting. TypeScript 5.5 added --noCheck, which skips the normal type-checking phase during emit.
A simple declaration-only command is:
tsc --noCheck \
--declaration \
--emitDeclarationOnly \
--outDir dist/typesThis command still parses the files and reports certain errors that prevent emission. It does not prove that the program's types are correct. Run checking separately:
tsc --noEmitIn a build system, these commands can run concurrently when they do not write to the same output directory. For example, JavaScript bundling can write to dist/js, declaration emission can write to dist/types, and checking can write only to the terminal or a report file.
| Job | Main purpose | Does full type checking? |
|---|---|---|
| `tsc --noEmit` | Find type errors | Yes |
| `tsc --noCheck --emitDeclarationOnly` | Emit `.d.ts` files | No |
| JavaScript bundler | Produce runtime files | Usually no |
Third-party declaration emitters use the same isolated-file assumption. A tool must explicitly support isolatedDeclarations; a general JavaScript transpiler cannot automatically produce correct TypeScript declarations merely because it can parse TypeScript.
Limitations and failure modes
The split workflow does not make invalid types valid. If an exported function has an inferred return type that depends on another module, an isolated emitter may not have enough information. Add an explicit return type.
Some tools generate one declaration per source file but do not bundle declarations into one public entry point. If consumers expect a single index.d.ts, run a declaration bundler after the parallel step.
Watch for these problems:
- The checker and emitter use different
tsconfig.jsonfiles. - The emitter does not understand path aliases or package exports.
- Generated declarations include private files that should not be published.
- The build reports success because
--noChecksucceeded while the separate checker failed. - Two jobs write to the same
.d.tspath.
A safe CI pipeline treats checking as required, even when declaration emission succeeds.
Choosing this approach
Use parallel declaration generation when declaration output is a measurable bottleneck and the project can adopt explicit public annotations. Keep ordinary tsc declaration emit when the project is small, inference-heavy, or easier to maintain with one integrated compiler pass.
Measure both workflows with the same clean and warm builds. Parallelism helps most in large projects with many independent modules. It may add setup and coordination overhead in a small project.
Exercise
What must still run when a declaration emitter uses --noCheck?
Show answer
A separate full type-checking command such as tsc --noEmit must run, because declaration emission alone does not validate the program's types.