microsoft / microsoft/TypeScript
Intersection, Union depends on type variable instantiation order
Nadie ha tomado este issue todavía.
- Lenguaje dominante
- Go
- Estrellas
- 111k
- Forks
- 14.3k
- Merge medio
- 1 d 19 h
- PR fusionados (30 d)
- 117
Descripción
🔎 Search Terms
generic type variable intersection union order
🕗 Version & Regression Information
- This is the behavior in every version I tried, and I reviewed the FAQ for entries about Generics
⏯ Playground Link
💻 Code
type Union<A, B> = A | B
type UnionAny<T> = Union<T, any>
type UnionUnknown<T> = Union<unknown, T>
// these should all be the same type but are respectively: any, any, unknown
type UA0 = Union<unknown, any>
// ^?
type UA1 = UnionAny<unknown>
// ^?
type UA2 = UnionUnknown<any>
// ^?
type Intersect<A, B> = A & B
type IntersectAny<T> = Intersect<T, any>
type IntersectNever<T> = Intersect<never, T>
// these should all be the same type but are respectively: never, any, never
type AN0 = Intersect<never, any>
// ^?
type AN1 = IntersectAny<never>
// ^?
type AN2 = IntersectNever<any>
// ^?
🙁 Actual behavior
The types UA0, UA1 are resolved as any and UA2 is resolved as unknown. These all map down to the same union of unknown and any, so should all be the same type.
The types AN0, AN2 are resolved as never and AN1 resolved as any. These all map down to be the intersection of any and never, so should all be the same type.
🙂 Expected behavior
I expect UA0, UA1 and UA2 to resolve as the same type (probably any, but preferably unknown)
I expect AN0, AN1 and AN2 to resolve as the same type (probably never)
Additional information about the issue
No response
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
Comienza con el Workbench Repro y compara los tipos resueltos de UA0, UA1, UA2, AN0, AN1 y AN2. Rastrea el comportamiento del type-checker para la instanciación genérica, las uniones y las intersecciones; se considera terminado cuando las expresiones equivalentes se resuelven de forma coherente y se cumplen los tipos esperados del repro.
Escrito por el modelo de indexación a partir del texto del issue.
Evaluación
- Stack tecnológico
- typescript
- Área
- compilers
- Tipo de issue
- Error
- Dificultad
- 5/5
- Tiempo estimado
- Más de una semana
- Estado de actividad
- Estancado
- Claridad
- Bien especificado
- Aptitud para principiantes
- 30/100