Skip to content

[api-extractor] API report shows spurious diffs because compiler emits inferred types inconsistently #1958

@dmichon-msft

Description

@dmichon-msft

Is this a feature or a bug?

  • Feature
  • Bug

Please describe the actual behavior.
TypeScript does not define the output order of the constituents of a union type. As a result of this, the output from API-extractor is inconsistent between fresh builds and incremental builds. From discussion with the TypeScript team, this is related to the order of loading of types and whether or not certain types need to be instantiated to type check the set of files that were built during the compilation.

The default sort order for union type constituents is based on the internal debug id, which is assigned when the type is instantiated.

If the issue is a bug, how can we reproduce it? Please provide detailed steps and include a GitHub branch if applicable. Your issue will get resolved faster if you can make it easy to investigate.
https://github.com/dmichon-msft/union-type-order-demo
Repro steps:

  1. Increment value of incrementStep1 in index.ts. Run npm run build. Observe order of export const test declaration.
  2. Increment value of incrementStep2 in B.ts. Run npm run build. Observe order of export const test declaration.
  3. Repeat (1) if necessary.

The order will change depending on which files needed recompilation.
The order directly matches that which is output in lib/index.d.ts, which is what changes.

What is the expected behavior?
Since API extractor is concerned with substantive changes, it should define a standard (potentially configurable, but not required) sort order for the constituents of union types, regardless of the order output by TypeScript. This should be similar to the sorting of interface members that api-extractor already performs.

If this is a bug, please provide the tool version, Node.js version, and OS.

  • Tool: api-extractor
  • Tool Version: 7.8.12, with TypeScript 3.7.5
  • Node Version: 10.19.0
    • Is this a LTS version? Yes
    • Have you tested on a LTS version? Yes
  • OS: Windows 10

Edited 6/23@1:29 PM: simplified repro.

Metadata

Metadata

Assignees

No one assigned

    Labels

    needs designThe next step is for someone to propose the details of an approach for solving the problem

    Type

    No type

    Projects

    Status

    AE/AD

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions