microsoft / microsoft/TypeScript
`keyof` on homomorphic mapped type over an array thinks keys are function types
Nadie ha tomado este issue todavía.
- Lenguaje dominante
- Go
- Estrellas
- 111k
- Forks
- 14.4k
- Merge medio
- 1 d 19 h
- PR fusionados (30 d)
- 117
Descripción
Bug Report
Creating a mapped type (where each value is just the key - { [K in keyof T]: K }) when applied over a generic type T, where T has been passed as an array type, somehow manages to resolve the keys of an array as functions. I've read the FAQ about homomorphic mapped types but I can't imagine the K in K in keyof T ending up as a function type - no matter what the T eventually becomes.
🔎 Search Terms
keyof, array, types, type constructors
🕗 Version & Regression Information
- This is the behavior in every version I tried, and I reviewed the FAQ for entries about homomorphic mapped types
Tested on 3.9.7, 4.2.3.
⏯ Playground Link
Playground link with relevant code
💻 Code
type Keys<T> = {
[K in keyof T]: K;
}[keyof T];
type GT = Keys<string[]>;
// ^ Hover here. Keys are functions ???

🙁 Actual behavior
Keys applied over an array, returns a union of functions.
🙂 Expected behavior
Keys applied over an array, should return the property names of the array.
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
Reproduce el comportamiento del TypeScript Playground enlazado utilizando el ejemplo de Keys con string[]. Empieza investigando cómo gestiona el compilador keyof y los tipos mapeados homomórficos para arrays; estará terminado cuando Keys<string[]> se resuelva en la unión de nombres de propiedades del array en lugar de en una unión de funciones.
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
- 35/100