rushstack icon indicating copy to clipboard operation
rushstack copied to clipboard

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

Open baileympearson opened this issue 2 years ago • 1 comments

Summary

This is a duplicate of https://github.com/microsoft/rushstack/issues/3094, but I wasn't sure how to get eyes on it so I created another ticket. Our use case is slightly different too. Feel free to close this in favor of https://github.com/microsoft/rushstack/issues/3094.

We (node-mongodb-native) use api-extractor to generate a d.ts file for the mongodb Node driver. Our library supports a number of optional features, which we let users configure by installing dependencies we have specified as peer optional dependencies. Internally, we import the types for the peer optional dependencies for our internal use but everywhere they're used they're marked @internal.

When we generate the rolled up d.ts file, the internal usages are correctly stripped out but the imports remain. This wouldn't be an issue if we had a hard dependency on these packages, because then they'd be installed for users by our package. For users who choose not to install these peer optional dependencies this is problematic because the generated d.ts file attempts to import from packages that are not present.

Repro steps

I've included a sample reproduction here: https://github.com/baileympearson/unused-imports-reproduction/tree/main.

Steps to reproduce are in the readme.

Expected result:

Imports for types and values that are only used internally should not be present in the generated d.ts file.

Actual result:

Imports for types and values that are only used internally are present in the generated d.ts file.

Details

Standard questions

Please answer these questions to help us investigate your issue more quickly:

Question Answer
@microsoft/api-extractor version? ^7.35.1
Operating system? Mac
API Extractor scenario? rollups (.d.ts)
Would you consider contributing a PR? Yes! If it isn't too involved.
TypeScript compiler version? ^5.1.6
Node.js version (node -v)? Node20

baileympearson avatar Aug 01 '23 17:08 baileympearson