-
Notifications
You must be signed in to change notification settings - Fork 13k
Open
Labels
Awaiting More FeedbackThis means we'd like to hear from more people who would be helped by this featureThis means we'd like to hear from more people who would be helped by this featureDomain: Type DisplayBugs relating to showing types in Quick Info/Tooltips, Signature Help, or Completion InfoBugs relating to showing types in Quick Info/Tooltips, Signature Help, or Completion InfoSuggestionAn idea for TypeScriptAn idea for TypeScript

Description
In DefinitelyTyped, $ExpectType
assertions depend on a type having a consistent string represenation across TypeScript versions.
It looks like the ordering of union types is dependent on some implementation details that change between versions. When we output unions as strings, we should sort them in some consistent way first instead of just using whatever order we happened to use internally.
I would suggest this ordering:
- numeric literals, low to high
- string literals, low to high (by
<
) - named types (including type aliases, enum, class and interface names), by name
- function literals: by length (
() => void
before(x: number) => void
), then by parameter name, then by parameter type - type literals: Sorted smallest to largest (
{ x: number }
before{ x: number, y: number }
); and type literals of the same size should be alphabetically sorted by property ({ a: number }
) before{ b: number }
) or by the sorting of values ({ s: "a" }
before{ s: "b" }
)
Of course, another solution would be to try to handle this in $ExpectType
by parsing out unions and allowing it if any sorting is valid. But it is strange in TS to see a string literal union displayed in a seemingly random order.
mausch, glen-84, shilman, domyen, alc-1 and 24 more
Metadata
Metadata
Assignees
Labels
Awaiting More FeedbackThis means we'd like to hear from more people who would be helped by this featureThis means we'd like to hear from more people who would be helped by this featureDomain: Type DisplayBugs relating to showing types in Quick Info/Tooltips, Signature Help, or Completion InfoBugs relating to showing types in Quick Info/Tooltips, Signature Help, or Completion InfoSuggestionAn idea for TypeScriptAn idea for TypeScript