microsoft / microsoft/TypeScript

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

オープン
#63,132 コメント 2 件 リアクション 0 件 担当者 1 名 GitHub で見る

@ahejlsberg がすでに取り組んでいます。

2026年2月13日 から。

Needs Investigation
主要言語
Go
スター
111k
フォーク
14.3k
平均マージ
2日 4時間
マージ済み PR(30日)
132

説明

🔎 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.

コントリビューションガイド

コントリビューションガイドを開く

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

評価

この issue はまだ評価されていません。

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。