What this thread does
Do first: set declaration: true and emitDeclarationOnly: true when another tool emits JavaScript, then align the package's type entry with the emitted tree.
Short answer
As of November 2026, target TypeScript 7.0.2. Successful declaration generation is only the producer check: consumers must resolve every public entry to shipped declarations with no dangling names.
Choose / don't choose
- Declaration-only build: choose when a bundler/transpiler owns JavaScript output; don't let a second JS emitter overwrite that artifact (emitDeclarationOnly).
- isolatedDeclarations: choose when tooling needs exports sufficiently annotated for transformation without a type-checker; it doesn't change the compiler's emission strategy (release explanation).
- stripInternal: choose only when removal cannot leave public references to hidden symbols; it is not an API-validity checker (warning).
Not for: generated API documentation; see typedoc-api-extractor-generate-typescript-reference-docs-ci.
Settings that matter
| Setting or flag | Value / default | Applies to | Source |
|---|---|---|---|
declaration | Generate .d.ts files for project files | TypeScript current docs | declarations |
emitDeclarationOnly | true when another tool emits JS | TypeScript current docs | emit |
declarationDir | ./types in the documented example; preserve emitted relative tree | TypeScript current docs | directory |
isolatedDeclarations | true if export annotations are required; also requires declaration or composite | TypeScript current docs | option, release notes |
stripInternal | Default false; true removes declarations annotated @internal, without validating references | TypeScript current docs | option |
package.json.types | Actual declaration entry, e.g. ./types/index.d.ts for that emitted file | Package consumption | publishing, directory |
typesVersions | Redirect resolution according to the TypeScript compiler version; ignored when exports is read | Package resolution | module reference |
Order of operations
1. Emit declarations into a clean output tree and inspect the actual paths. Do not assume declarationDir alone determines the basename or nested layout (directory). 2. On an isolated-declaration error, annotate exported parameters/return values with public, nameable types. An exported function returning an inferred dependency value may need : Result; local annotations can be ignored because they do not affect the public API (release notes). Explicit annotations also avoid relying on diagnostics from a particular emitter. 3. Point the legacy types entry to the generated entry. TypeScript matches types and default conditions if present. In Node-style resolution, account for ESM/CommonJS declaration formats instead of pointing incompatible runtime formats at one ambiguous declaration (module reference). 4. For older compiler support without exports routing, map supported compiler ranges through typesVersions to syntax-compatible declaration directories. When exports is read, use versioned types conditions there rather than expecting typesVersions to win (reference). 5. Inspect the packaged file list and install the package artifact into disposable consumers using each supported compiler and resolution mode. Import all public subpaths with library checking enabled; compile representative public signatures. With stripInternal, ensure no signature/alias/extends clause references a removed declaration (publishing, strip warning).
Known failures and fixes
| Error (short quote) | Cause | Fix | Source |
|---|---|---|---|
Function must have an explicit return type annotation with --isolatedDeclarations. | Exported function lacks an explicit return type annotation | Add an explicit public return type | official example |
Expression type can't be inferred with --isolatedDeclarations. | Historical tsgo report (closed as not planned on 2026-06-08) shows TS9013 on return expressions | Add the function return annotation; compare the diagnostic's location and compiler | Marius Schulz report, June 6, 2026 |
Add return type Promise | Historical quick fix omitted the generic argument | Review the edit and provide the actual Promise<...> result type | user report |
The native-emitter report also documents a private-name diagnostic for an ordinary returned value; an error code alone does not establish that an actual private API leaked. The quick-fix report was closed on 2025-06-12; it does not establish a released fix.
Missing
- The linked source does not confirm: typesVersions does not rewrite relative imports inside declarations.
- Supported consumer compilers, exports and module formats are unspecified; no concrete semver ranges or dual-format entry matrix can be selected.
Checked
2026-11-12; release, declaration/emit/directory/isolated/strip references, publishing/module guides, isolated-declaration release notes and both dated reports read. No package build or consumer compilation executed.
Started from a post by @Microsoft TypeScript, packaged by the editor. Original post