Skip to content

typescript: a dependency staged with --library keeps the declarations under its build directory - #1941

Merged
swapnilpaliwal-sd merged 1 commit into
apps/integration-0.1.10from
fix/ts-library-build-dirs
Oct 13, 2026
Merged

swapnilpaliwal-sd merged 1 commit into
apps/integration-0.1.10from
fix/ts-library-build-dirs

Conversation

@swapnilpaliwal-sd

Copy link
Copy Markdown
Contributor

Symptom

A TypeScript call into a package passed with --library stays ambiguous_unknown when the package keeps its declarations in a build directory:

  • a root .d.ts that re-exports ./dist/...: only the root files were staged (one measured package: 78 methods of ~1,600 declaration files);
  • a package whose every declaration is under dist/types/ (reached through an exports map types condition): no TypeScript was staged at all (0 methods), only its JavaScript.

Cause

The TypeScript analyzer walked a library root with the project skip list (dist, build, out), and detection looks for TypeScript near the top of the tree. JavaScript already distinguishes a library root (libraryRoot); TypeScript did not.

Change

  • TypeScriptAnalysisOptions.libraryRoot; extractProject passes opts.library === true. A library walk keeps TS_BUILD_OUTPUT_DIRECTORIES; nested node_modules stays skipped.
  • In library mode, a root no detector calls TypeScript whose package.json declares types (types / typings, or a types condition anywhere in exports) is analysed as a TypeScript project.
  • The project under analysis is unchanged.

Evidence

package shape TS methods before after
root .d.ts re-exporting ./dist 78 8,238
declarations only under dist/types 0 218
controls (declarations at the root / in a non-build dir) 377 · 1,104 · 12,335 unchanged

On a 5-file client fixture with the libraries staged, four previously unresolved calls now resolve to library declarations (boundary_lib); unknown sites 22 → 17. The remaining unknowns are other constructs (a default import re-exported as named, a namespace re-exported through export { z }, a method on an awaited return value, a library component used as a JSX element) and are not addressed here.

Tests

  • discovery: a-library-keeps-the-declarations-under-its-build-directory (control: the same tree as the project still skips dist/) and a-library-whose-declarations-all-sit-in-dist-is-typescript (control: an untyped package gets no typescript/). Both fail without the change.
  • typescript-tests.ts 49/49; tsc --noEmit clean.

Cost

A library whose build directory is large stages more declaration files (one package: ~2 min, unchanged, since its JavaScript under dist/ was already walked; the TypeScript IR is 74 MB next to 3.6 GB of JavaScript IR).

🤖 Generated with Claude Code

… under its build directory

A library root was walked with the project skip list, so dist/, build/ and out/ were
skipped. A package whose root .d.ts re-exports ./dist/... staged only the root files, and
a package whose every declaration sits under dist/types/ was not detected as TypeScript at
all. Every TypeScript call into such a package stayed ambiguous_unknown although it was
passed with --library.

The TypeScript analyzer now takes libraryRoot (as the JavaScript one does), and a library
walk keeps the build-output directories. A library root that no detector calls TypeScript
but whose package.json declares types (types/typings, or a types condition in exports)
is analysed as one. The project under analysis is unchanged: dist/ stays skipped.

Two discovery checks, each with a control: a re-exporting package as library vs as project,
and a dist-only typed package vs an untyped one.

Co-authored-by: axiomcode-bot[bot] <334110751+axiomcode-bot[bot]@users.noreply.github.com>
@swapnilpaliwal-sd
swapnilpaliwal-sd merged commit 7456ada into apps/integration-0.1.10 Oct 13, 2026
12 checks passed
@swapnilpaliwal-sd
swapnilpaliwal-sd deleted the fix/ts-library-build-dirs branch October 13, 2026 07:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant