Skip to content

[api-extractor] Prune unused imports from trimmed declaration rollups - #6240

Open
Ian Clanton-Thuon (iclanton) wants to merge 1 commit into
microsoft:mainfrom
iclanton:fix/api-extractor-trim-unused-imports
Open

Ian Clanton-Thuon (iclanton) wants to merge 1 commit into
microsoft:mainfrom
iclanton:fix/api-extractor-trim-unused-imports

Conversation

@iclanton

Copy link
Copy Markdown
Member

Summary

Consumers should not need to install an optional dependency just to type-check a package whose released declarations never use it. Omit imports used only by declarations removed from an alpha, beta, or public .d.ts rollup.

Fixes #4260.

Details

Track which import bindings are actually used while emitting surviving declarations and re-exports, including inline import() types and namespace exports. Emit those imports before the declarations in their existing order. A retained signature still gets its import even if the imported symbol has a less-public release tag. The untrimmed rollup and release-tag semantics are unchanged.

How it was tested

  • rush --quiet build -o @microsoft/api-extractor -o api-extractor-scenarios --production passes on the PR commit.
  • Restoring the previous unconditional import emission fails the new alpha, beta, and public snapshots; the untrimmed snapshot stays unchanged.
  • rush change --verify --target-branch microsoft/main --no-fetch passes.

Track imports referenced by retained declarations and re-exports. Keep imports used by surviving signatures regardless of the imported release tag, and leave the untrimmed rollup unchanged.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Needs triage

Development

Successfully merging this pull request may close these issues.

[api-extractor] Internally used types generate an unused import in dtsRollup

1 participant