-
Notifications
You must be signed in to change notification settings - Fork 709
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
feat: sort unions #2502
Labels
enhancement
Improved functionality
Comments
Gerrit0
added
enhancement
Improved functionality
and removed
bug
Functionality does not match expectation
labels
Feb 14, 2024
More design needed before this can be implemented. What happens if it isn't just numbers?
|
|
This was referenced Jul 27, 2024
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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 of1
, 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:
(it works on twoslash but not on the playground because they use different stdlibs)
The text was updated successfully, but these errors were encountered: