microsoft / microsoft/TypeScript
Use a consistent ordering when writing union types
Nadie ha tomado este issue todavía.
- Lenguaje dominante
- Go
- Estrellas
- 111k
- Forks
- 14.3k
- Merge medio
- 2 d 4 h
- PR fusionados (30 d)
- 132
Descripción
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 (
() => voidbefore(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.
Guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Línea de trabajo
No se especifica ningún archivo ni prueba. Empieza siguiendo el recorrido del compilador que convierte los tipos unión en cadenas y compáralo después con las aserciones $ExpectType de DefinitelyTyped; se considera terminado cuando los miembros de la unión siguen un orden determinista entre distintas versiones de TypeScript.
Escrito por el modelo de indexación a partir del texto del issue.
Evaluación
- Stack tecnológico
- typescript
- Área
- compilers
- Tipo de issue
- Nueva funcionalidad
- Dificultad
- 5/5
- Tiempo estimado
- Más de una semana
- Estado de actividad
- Estancado
- Claridad
- Bastante claro
- Aptitud para principiantes
- 35/100