typedoc icon indicating copy to clipboard operation
typedoc copied to clipboard

Sorting of union types is non-deterministic

Open imtuanpham opened this issue 1 year ago • 2 comments

This issue is related to https://github.com/TypeStrong/typedoc/issues/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 avatar Oct 16 '24 05:10 imtuanpham

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 avatar Oct 18 '24 15:10 Gerrit0

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

export type Type1 = 'type1' & {};

Gerrit0 avatar Oct 18 '24 15:10 Gerrit0