Skip to content
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

[api-extractor] API report does not indicate if a class was type exported. #4771

Open
CraigMacomber opened this issue Jun 7, 2024 · 0 comments

Comments

@CraigMacomber
Copy link

Summary

It is possible to type export a class. Doing so impacts how it can be used (it becomes impossible to access statics, use instanceof, extend it, etc) but this is not reflected in the API report.

Repro steps

reexport a class as a type only export.
For example, define a class:

export class Foo {}

then when reexporting it (for example in index.ts):

export { type Foo } from "foo";

Expected result: API report somehow indicates that the class has only been type exported.

Actual result: No change in the API report from adding type to the export.

Details

This was encountered in microsoft/FluidFramework#21351

Since TypeScript does not provide a nice syntax for type only exporting a class inline, I think the best way for API Extractor to handle this might be to include a comment on the class saying it is type-only. Given the limitation (other bug linked below) supporting this in rollups, I think such a comment would be extra useful.

This is related to #3616 where this same approach results in incorrect rollups.

That thread implies the use-case for this pattern is hiding the constructor: while I also benefit from that, my use-case is preventing subclassing, and disallowing access to statics (which instanceof implicitly uses). I was a bit surprised that API extractor allows this, but I think its a useful feature.

The fact that it does not work correctly in rollups is unfortunate, however my project does not use API extractor rollups (due to them breaking nominal typing when used with multiple import paths) so that does not apply to us.

Standard questions

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

Question Answer
@microsoft/api-extractor version? @microsoft/[email protected] (with a patch, see https://github.com/microsoft/FluidFramework/blob/main/patches/%40microsoft__api-extractor%407.45.1.patch )
Operating system? Linux
API Extractor scenario? reporting (.api.md)
Would you consider contributing a PR? No
TypeScript compiler version? 5.4.5
Node.js version (node -v)? v18.17.1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: AE/AD
Development

No branches or pull requests

1 participant