microsoft / microsoft/TypeScript
`extends any ?` may return right hand in conditional 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
TypeScript Version: 4.0.5
Search Terms:
- type inference
- extends any
- conditional types
- right hand
Expected behavior:
type D1 = X1 <O1> returns false.
Actual behavior:
In the code below, type D1 = X1<O1> seems to return false, but it actually returns true.
If you change the seemingly irrelevant right-hand type in extends any ? written for union distribution to undefined, it will behave as intended.
Related Issues:
Code
type X1<T> = IfEq<
AllKeys1<T>,
keyof T,
true,
false
>;
type X2<T> = IfEq<
AllKeys2<T>,
keyof T,
true,
false
>;
type IfEq<X, Y, T, E> = [X] extends [Y] ? ([Y] extends [X] ? T : E) : E;
// AllKeys<{ x: ... } | { x: ...; y: ... }> -> "x" | ("x" | "y") -> "x" | "y"
type AllKeys1<O extends Object> = O extends any ? keyof O : never;
type AllKeys2<O extends Object> = O extends any ? keyof O : undefined;
type O1 = { x: string; y: number } | { x: boolean; z: number }
type A1 = AllKeys1<O1> // "x" | "y" | "z"
type A2 = AllKeys2<O1> // "x" | "y" | "z"
type B = keyof O1 // "x"
type C1 = IfEq<A1, B, true, false> // false
type C2 = IfEq<A2, B, true, false> // false
type D1 = X1<O1> // true ???
type D2 = X2<O1> // false
type O2 = { x: string; y: number } | { x: boolean; y: Object }
type E1 = X1<O2> // true
type E2 = X2<O2> // true
Output
"use strict";
Compiler Options
{
"compilerOptions": {
"noImplicitAny": true,
"strictNullChecks": true,
"strictFunctionTypes": true,
"strictPropertyInitialization": true,
"strictBindCallApply": true,
"noImplicitThis": true,
"noImplicitReturns": true,
"alwaysStrict": true,
"esModuleInterop": true,
"declaration": true,
"experimentalDecorators": true,
"emitDecoratorMetadata": true,
"moduleResolution": 2,
"target": "ES2017",
"jsx": "React",
"module": "ESNext"
}
}
Playground Link: Provided
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 la reproducción proporcionada en Playground usando TypeScript 4.0.5 y compara los resultados de los tipos condicionales para D1, D2, E1 y E2. Sigue el procesamiento de los tipos condicionales distributivos por parte del compilador y verifica que los resultados esperados y reales informados se resuelvan de forma coherente sin cambiar los demás casos.
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
- 4/5
- Tiempo estimado
- 3-5 días
- Estado de actividad
- Estancado
- Claridad
- Bastante claro
- Aptitud para principiantes
- 38/100