[api-extractor] Union types extracted from declaration files are unstable
Opened this issue · 0 comments
Summary
The union types extracted from TypeScript declaration files are possibly unstable.
In rspack, we run API checks using api-extractor to ensure the API change is correct. The result shows the union type is not ordered (or sorted), causing the snapshot being not usable. The result of an diff
command for both etc
and temp
file.
Repro steps
It's hard to reproduce as this is related to some internal declaration inlining logics.
Expected result:
The union output should be stable.
Actual result:
The union output is not stable.
Details
As what has been discussed in microsoft/TypeScript#17944 issue, tsc does not seem to provide the stable output for the union type. Potential fix might be sorting the output of the union types like microsoft/TypeScript#32224, but I don't know whether it's good to ship it in on the tsc side or on the api-extractor side. If you have any possible recommended solution on this one, please let me know.
Possible solution: Maybe we could sort the dts before passing to the api-extractor using formatters like https://typescript-eslint.io/rules/sort-type-constituents/.
Standard questions
Please answer these questions to help us investigate your issue more quickly:
Question | Answer |
---|---|
@microsoft/api-extractor version? |
7.43.1 |
Operating system? | MacOS |
API Extractor scenario? | reporting |
Would you consider contributing a PR? | Yes |
TypeScript compiler version? | 5.0.2 |
Node.js version (node -v )? |
18.16.0 |