Skip to content

[api-extractor] (fix) Fix module resolution for some type import declarations #5288

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

Monkeylordz
Copy link

@Monkeylordz Monkeylordz commented Jul 27, 2025

Summary

Fixes #5106.
Fixes #5126.

This PR makes a change to the ExportAnalyzer which fixes a regression bug where type import declarations were sometimes not resolved (and then treated as external) when using a moduleResolution other than node.

Additionally, this PR adds additional functionality to the api-extractor-scenarios runner script to allow scenarios to use custom compiler states. In addition to that, it adds a new scenario called bundlerModuleResolution that uses this functionality in order to test this fix.

Details

From what I could tell, this bug was introduced in api-extractor@7.49.0 as a result of updating to typescript@5.7.2. In previous versions, type import declaration nodes would always contain a StringNode in their argument field, which is used to get the mode. However, in 5.7.0 and after, these import declaration nodes may now contain a LiteralNode in certain situations. As a result, it would fail the isStringLiteralLike check and stop resolving the modules, leading to rollup types that include imports to types that don't exist. I introduced an extra check for these LiteralNodes that will then extract the intended StringNode, and this seems to fix the issue. It shouldn't introduce any regressions, as this only introduces a new code path and doesn't affect older ones.

Testing

This PR adds a scenario called bundlerModuleResolution (let me know if you have a better name) to test the fix. The default TSConfig for the scenarios is "moduleResolution": "node", so overrides the tsconfig to set "moduleResolution": "bundler". This is done with the following additional change:

Currently, the api-extractor-scenarios reuse the same compiler state, but this prevents using scenarios from testing functionality that is specific to certain tsconfig settings because that would require a new compiler state. This PR adds some new logic in run-scenario-helpers that creates a custom compiler state for scenarios that added a "compiler" option in the api-extractor-overrides.json file.

Impacted documentation

This shouldn't impact documentation, as it is a fix for a regression.

@Monkeylordz
Copy link
Author

@microsoft-github-policy-service agree

@Monkeylordz Monkeylordz changed the title Add ability for api-extractor-scenarios to customize the extractor compiler state [api-extractor] (fix) Fix module resolution for some type import declarations Jul 27, 2025
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
1 participant