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

Sorting of union types is non-deterministic #2751

Open
imtuanpham opened this issue Oct 16, 2024 · 2 comments
Open

Sorting of union types is non-deterministic #2751

imtuanpham opened this issue Oct 16, 2024 · 2 comments
Labels
bug Functionality does not match expectation needs reproduction Needs a minimal reproducible case

Comments

@imtuanpham
Copy link

This issue is related to #2502 but applies to non-literal types. Sorting of union types is non-deterministic.

Steps to reproduce the bug

export type Type1 = 'type1';
export type Type2 = { prop1: string; prop2: boolean };

/**
 * Some Interface
 */
export interface SomeInterface {
  someUnionType: Type1 | Type2;
}

Expected

image

Actual

Most of the times it shows
image

But sometimes it shows
image

(This is causing our CI pipeline to fail as we have a job to ensure the API Doc changes are included in pull requests)

Environment

@imtuanpham imtuanpham added the bug Functionality does not match expectation label Oct 16, 2024
@Gerrit0
Copy link
Collaborator

Gerrit0 commented Oct 18, 2024

I can't reproduce this. TypeDoc is using the the type as it is reported from TypeScript, which in the ~30 times I've run it, always puts "type1" second in the union.

image

@Gerrit0 Gerrit0 added the needs reproduction Needs a minimal reproducible case label Oct 18, 2024
@Gerrit0
Copy link
Collaborator

Gerrit0 commented Oct 18, 2024

You can work around this by forcing Type1 to introduce a new type:

export type Type1 = 'type1' & {};

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Functionality does not match expectation needs reproduction Needs a minimal reproducible case
Projects
None yet
Development

No branches or pull requests

2 participants