microsoft / microsoft/TypeScript

`Omit` causes function to lose contextual typing

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

まだ誰も着手していません。

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

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 P in the mapped type. (original mapping was more complicated, but identity mapping seems to trigger it too)

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

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

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. 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

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

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