microsoft / microsoft/TypeScript
Type can't `keyof`
Abierto
Nadie ha tomado este issue todavía.
Needs Investigation
- Lenguaje dominante
- Go
- Estrellas
- 111k
- Forks
- 14.4k
- Merge medio
- 1 d 19 h
- PR fusionados (30 d)
- 117
Descripción
🔎 Search Terms
- keyof
🕗 Version & Regression Information
- This is a crash
⏯ Playground Link
No response
💻 Code
export type IsEqual<A, B> =
(<T>() => T extends A ? 1 : 2) extends
(<T>() => T extends B ? 1 : 2) ? true : false
export type IsNotEqual<A, B> =
(<T>() => T extends A ? 1 : 2) extends
(<T>() => T extends B ? 1 : 2) ? false : true
export interface Entries<X> {
100000: [true extends (
& IsNotEqual<X, ArrayConstructor>
// Simplifying the problem here allows for the removal of the next line.
& ([X] extends [ObjectConstructor] ? true : false)
) ? true : false, {
check: (
& IsNotEqual<X, ArrayConstructor>
& ([X] extends [ObjectConstructor] ? true : false)
),
x: X
}]
[key: number & {}]: [boolean, any]
}
type Mapping<
X,
E extends Entries<X> = Entries<X>
> = {
[ K in keyof E
as true extends (
IsEqual<E[K & number][0], true>
) ? K : never
]: E[K & number][1]
}
type A0 = keyof Mapping<ObjectConstructor>
// ^? type A0 = 100000
type A1 = ObjectConstructor extends infer T ? Mapping<T> : never
// ^? type A1 = { 10000: { check: true; x: ObjectConstructor } }
type A2 = ObjectConstructor extends infer T ? keyof Mapping<T> : never
// ^? type A2 = never
type A3 = [ObjectConstructor] extends [infer T] ? keyof Mapping<T> : never
// ^? type A3 = never
type A4 = keyof (ObjectConstructor extends infer T ? Mapping<T> : never)
// ^? type A4 = 11000
Output
export {};
// ^?
Compiler Options
{
"compilerOptions": {
"strict": true,
"noImplicitAny": true,
"strictNullChecks": true,
"strictFunctionTypes": true,
"strictPropertyInitialization": true,
"strictBindCallApply": true,
"noImplicitThis": true,
"noImplicitReturns": true,
"alwaysStrict": true,
"esModuleInterop": true,
"declaration": true,
"target": "ES2017",
"jsx": "react",
"module": "ESNext",
"moduleResolution": "node"
}
}
Playground Link: Provided
🙁 Actual behavior
In the case of A2, the type obtained through the operation cannot be used with keyof to obtain the Keys of the corresponding type.
🙂 Expected behavior
type A2 = 11000
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 la reproducción proporcionada de TypeScript Playground y compara A2 con A0–A4, centrándote en la evaluación de keyof para los tipos condicionales y mapeados mostrados. Se considera terminado cuando el fallo está resuelto y A2 se evalúa como 11000 sin cambiar el comportamiento esperado de los ejemplos adyacentes.
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
- Bastante claro
- Aptitud para principiantes
- 30/100