microsoft / microsoft/TypeScript
`Omit` causes function to lose contextual typing
オープン
まだ誰も着手していません。
Needs Investigation
- 主要言語
- Go
- スター
- 111k
- フォーク
- 14.3k
- 平均マージ
- 2日 4時間
- マージ済み PR(30日)
- 132
説明
🔎 Search Terms
implicit any contextual type
🕗 Version & Regression Information
- This changed between versions 5.9.3 and 6.0 - rc
⏯ Playground Link
💻 Code
declare let x: { function: string }
export type AssertableState<T> = {
[P in keyof T as P]: (value: T[P]) => void;
}
declare function assert_state<T extends object>(o: T, state: AssertableState<T>): void;
assert_state(x, {
function: v => { } // v is string
})
declare function assert_state_bad<T extends object>(o: T, state: Omit<AssertableState<T>, "">): void;
assert_state_bad(x, {
function: v => { } // error - v is implictly any
})
🙁 Actual behavior
The call to assert_state_bad fails because v is implicitly typed as any
🙂 Expected behavior
Either should pass as in 5.9.3
Additional information about the issue
- Works without the
Omit - Works without the
as Pin the mapped type. (original mapping was more complicated, but identity mapping seems to trigger it too)
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
調査の方向性
まず、リンクされた Playground の例を TypeScript 5.9.3 と 6.0-rc で再現し、Omit あり・なしの場合と identity mapped type の場合でコンテキスト型付けを比較します。Omit でラップされた mapped type の型チェック経路を追跡します。完了の条件は、コールバックパラメーターが string として推論され、報告されている implicit-any の失敗が発生しなくなることです。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- typescript
- 領域
- compilers
- issue の種類
- バグ
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 活発さ
- 静か
- 明瞭さ
- おおむね明確
- 初心者へのやさしさ
- 48/100