Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Sorting of union types is non-deterministic #2751

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

Sorting of union types is non-deterministic #2751

imtuanpham opened this issue Oct 16, 2024 · 2 comments
Labels
needs reproduction Needs a minimal reproducible case - https://gist.github.com/Rich-Harris/88c5fc2ac6dc941b22e7996af05d

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 - https://gist.github.com/Rich-Harris/88c5fc2ac6dc941b22e7996af05d 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' & {};

@Gerrit0 Gerrit0 closed this as not planned Won't fix, can't repro, duplicate, stale Nov 1, 2024
@Gerrit0 Gerrit0 removed the bug Functionality does not match expectation label Feb 2, 2025
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
needs reproduction Needs a minimal reproducible case - https://gist.github.com/Rich-Harris/88c5fc2ac6dc941b22e7996af05d
Projects
None yet
Development

No branches or pull requests

2 participants