microsoft / microsoft/TypeScript

Regression: Mapped types are no longer homomorphic when wrapped in certain conditional types

Abierto
#63,132 2 comentarios 0 reacciones 1 asignado Ver en GitHub

@ahejlsberg ya está trabajando en esto.

Desde el 13/2/2026.

Needs Investigation
Lenguaje dominante
Go
Estrellas
111k
Forks
14.3k
Merge medio
2 d 4 h
PR fusionados (30 d)
132

Descripción

🔎 Search Terms

"homomorphic" "keyof" "extends"

🕗 Version & Regression Information
  • This changed between versions 3.8.3 and 3.9.7
⏯ Playground Link

https://www.typescriptlang.org/play/?#code/C4TwDgpgBA0hIFkCGYA8AVAfFAvFA1vAPYBmU6UEAHsBAHYAmAzlAAoBORk7ocIUAfigBvKAG0YUAJZ0CxMugC6ALlhQAvlFV0IANwjsA3AChjoSFAAauWPGRo6AVwC2AIwOZDQA

💻 Code
type KeyMap<T> = keyof T extends PropertyKey ? { [K in keyof T]: K } : never;

type X = KeyMap<number>;
🙁 Actual behavior

X is evaluated to

type X = {
    toString: "toString";
    toFixed: "toFixed";
    toExponential: "toExponential";
    toPrecision: "toPrecision";
    valueOf: "valueOf";
    toLocaleString: "toLocaleString";
}
🙂 Expected behavior

X should be evaluated to number because according to the FAQ,

Mapped types declared as { [ K in keyof T ]: U } where T is a type parameter are known as homomorphic mapped types, which means that the mapped type is a structure preserving function of T. When type parameter T is instantiated with a primitive type the mapped type evaluates to the same primitive.

Additional information about the issue

Replacing PropertyKey with either unknown or any fixes the issue for some reason.

Guía de contribución

Abrir la guía de contribución

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Evaluación

Este issue todavía no se ha evaluado.

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.