Description
Summary
export class Foo extends class {} {}
Produces:
declare const Foo_base: {
new (): {};
};
export declare class Foo extends Foo_base {
}
export {};
Putting an API-Extractor release tag on "Foo" results in an "ae-forgotten-export" that there is no release tag on "Foo_base".
However this is no clean way to put the release tag on "Foo_base" other than refactoring the code to explicitly export the base class.
Ideally extra non-exported types with mangled names which TSC adds as an implementation detail of d.ts files would not impact API-Extractor. I think suppressing the warning/error in this case would be the optimal outcome.
Unfortunately I don't think there is a truly robust way to detect this case just looking at the d.ts file, since developers can manually export types named SomeClass_base. (Note that in this case TSC may generate a name of the format SomeClass_base_1 to avoid the collision), but just suppressing the warning/error for all non-exported classes of the format SomeClass_base_1 or SomeClass_base would be enough for our use cases.
If adding a special case for this pattern is not a good solution, detecting these cases (as effectively as possible) as a heuristic to add a better error message for this case. For example:
The symbol "SomeClass_base" needs to be exported by the entry point index.d.ts. This type may have been implicitly generated by the TypeScript compiler for the base type of a class which extends an anonymous class expression. In this case this error can be resolved by explicitly exporting the result of that expression, then extending that exported constant.
Another option would be to include a config setting to opt out of this case being an error.
Repro steps
/**
* @alpha
*/
export class Foo extends class {} {}
Expected result: No errors, or a more specific error.
Actual result: Error: src/class-tree/testRecursiveDomain.ts:32:1 - (ae-forgotten-export) The symbol "RecursiveObject_base" needs to be exported by the entry point index.d.ts
Details
This came up with the schema system we are creating for Fluid-Framework's trees. All users of our schema system which export schema and use API-Extractor will hit this.
A real world example of this is in https://github.com/microsoft/FluidFramework/pull/18350/files/5a2309887741c6e4a7976b824f062960ec32f02a..7dcf01f1717e5f021e2c2c9f9238fa65038b3e47#diff-7006e9416c4e849ea87906ed645eab13666c035fe928e478446c9bd1cf0f4ea8
This pattern was partially adopted to work around microsoft/TypeScript#55832 : Using classes like this lets the compiler refer to them easier and avoid generating any
in some recursive cases. There are also other reasons we like this pattern (it allows apps to add methods to schema, works with instanceof, gets better intelisense).
I suspect other mixing type patterns might hit this as well.
Standard questions
Please answer these questions to help us investigate your issue more quickly:
Question | Answer |
---|---|
@microsoft/api-extractor version? |
3.38.3 |
Operating system? | Linux |
API Extractor scenario? | reporting (.api.md) |
Would you consider contributing a PR? | Yes if the fix is trivial |
TypeScript compiler version? | 5.1.6 |
Node.js version (node -v )? |
18.17.1 |
Metadata
Metadata
Assignees
Labels
Type
Projects
Status