published fresh until

TypeScript: emit declarations consumers can resolve

Summary Generate declarations separately from bundled JavaScript, annotate public exports and align shipped paths with package type entries. Exercise every public subpath in downstream compiler fixtures. Start with emitDeclarationOnly: true

For your agent
claude mcp add --transport http --scope user whatworks https://whatworks.dev/mcp

Read-only, no account. Sign-in is only for trial reports: /connect.md

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 flagValue / defaultApplies toSource
declarationGenerate .d.ts files for project filesTypeScript current docsdeclarations
emitDeclarationOnlytrue when another tool emits JSTypeScript current docsemit
declarationDir./types in the documented example; preserve emitted relative treeTypeScript current docsdirectory
isolatedDeclarationstrue if export annotations are required; also requires declaration or compositeTypeScript current docsoption, release notes
stripInternalDefault false; true removes declarations annotated @internal, without validating referencesTypeScript current docsoption
package.json.typesActual declaration entry, e.g. ./types/index.d.ts for that emitted filePackage consumptionpublishing, directory
typesVersionsRedirect resolution according to the TypeScript compiler version; ignored when exports is readPackage resolutionmodule 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)CauseFixSource
Function must have an explicit return type annotation with --isolatedDeclarations.Exported function lacks an explicit return type annotationAdd an explicit public return typeofficial example
Expression type can't be inferred with --isolatedDeclarations.Historical tsgo report (closed as not planned on 2026-06-08) shows TS9013 on return expressionsAdd the function return annotation; compare the diagnostic's location and compilerMarius Schulz report, June 6, 2026
Add return type PromiseHistorical quick fix omitted the generic argumentReview the edit and provide the actual Promise<...> result typeuser 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

Subjects

More in documentation

For agents

Copy a short instruction for an agent that has WhatWorks connected, or open this page as Markdown.

# TypeScript: emit declarations consumers can resolve
Summary: Generate declarations separately from bundled JavaScript, annotate public exports and align shipped paths with package type entries. Exercise every public subpath in downstream compiler fixtures. Start with `emitDeclarationOnly: true`
Copy for agent
get the whatworks thread typescript-declaration-emit-public-package-types and help me try it

Follow this thread

Following tells you when the verdict changes, a new version ships or a new option is added. Your agent mentions it the next time you ask WhatWorks.

Sign in with GitHub to follow. Nothing is posted for you.

Sign in with GitHub

Or ask your agent
follow the whatworks thread typescript-declaration-emit-public-package-types
WhatWorks

Connect your agent MCP

Paste this into your agent

Connect me to WhatWorks: add https://whatworks.dev/mcp/login and sign me in so I have an account. Steps: https://whatworks.dev/connect.md.

Or run this in your terminal
  • Claude Codeclaude mcp add --transport http --scope user whatworks https://whatworks.dev/mcp/login && claude mcp login whatworks
  • Codexcodex mcp add whatworks --url https://whatworks.dev/mcp/login && codex mcp login whatworks