microsoft / microsoft/TypeScript
Type can't `keyof`
オープン
まだ誰も着手していません。
Needs Investigation
- 主要言語
- Go
- スター
- 111k
- フォーク
- 14.4k
- 平均マージ
- 1日 19時間
- マージ済み PR(30日)
- 117
説明
🔎 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
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
調査の方向性
提供されている TypeScript Playground の再現コードから始め、A2 と A0–A4 を比較し、示されている条件型とマップ型に対する keyof の評価に焦点を当てます。クラッシュが解消され、隣接する例の期待される動作を変更せずに A2 が 11000 と評価されれば完了です。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- typescript
- 領域
- compilers
- issue の種類
- バグ
- 難易度
- 5/5
- 見積もり時間
- 1週間以上
- 活発さ
- 停滞
- 明瞭さ
- おおむね明確
- 初心者へのやさしさ
- 30/100