Description
Expected Behavior
Typedoc produces a webpage like this:
This union is bugged because it is in the wrong order (i.e. not sorted). This is because TypeDoc is just mirroring how TypeScript internally prints out the union.
Nathan Sanders explains that TypeScript does this internally because it builds the union data structure based on when the original types are first used. In other words, the type of 3
gets used first in the stdlib before the type of 1
, so then are printed out in the order that the types are first added to the set.
Nathan also suggests that in principle this could be fixed in the TypeScript repo upstream by adding all of the types type A = 1; type B = 2;
and so on in the first file of the stdlib so that they all get created in memory in order.
But for now, I propose that TypeDoc automatically sorts unions of numbers.
Steps to reproduce
Something like:
type Test = [1, 2, 3][number]
// ^? - type Test = 1 | 2 | 3
(it works on twoslash but not on the playground because they use different stdlibs)