microsoft / microsoft/TypeScript

Inference from annotated parameters of context-sensitive functions is order dependent

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

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

Bug Domain: check: Type Inference
主要言語
Go
スター
111k
フォーク
14.4k
平均マージ
1日 19時間
マージ済み PR(30日)
117

説明

🔎 Search Terms

inference annotated parameters context sensitive order

🕗 Version & Regression Information
  • This is the behavior in every version I tried
⏯ Playground Link

https://www.typescriptlang.org/play?ts=5.4.0-dev.20231118#code/CYUwxgNghgTiAEAzArgOzAFwJYHtXwxAGcMAeAFQBp4BBagIQD4AKHAIwCsAueAbwCh48TAA8e5ANyD4UHs1m1qo8QEp4AXkbwAbjizApQtnOPx6SjGPhUZPGms069B-gF8VPXfqn9CJZgJCyvAA5Ig4OCGU0gryPCQwWKgA5hYiDlq8rtFGJvEYiSlp1FAZfNluKj5+GAHSwWERUdKmzKYJSanCliVlWTm28HHwHUXd6RqZFe5SQA

💻 Code
declare function test<T, A, B>(obj: {
  ctx: T;
  a: (a: A, ctx: T) => void;
  b: (b: B, ctx: T, a: A) => void;
}): void;

test({
  ctx: 'foo',
  a: (a: string, ctx) => {},
  b: (b: string, ctx, a) => {},
});

test({
  ctx: 'foo',
  b: (b: string, ctx, a) => {},
  a: (a: string, ctx) => {},
});
🙁 Actual behavior

The second call doesn't infer properly

🙂 Expected behavior

I'd expect the second call to be inferred as good as the first one

Additional information about the issue

related to https://github.com/microsoft/TypeScript/issues/47599

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

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

はじめの一歩

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

調査の方向性

リンクされた TypeScript Playground で 2 つの呼び出しを再現し、それらの推論動作を比較してから、コンテキストを把握するために関連する issue #47599 を読んでください。型推論とコンテキスト型付けに関係する経路を調査してください。既存の例をリグレッションさせずに、2 番目のオブジェクトプロパティの順序でも 1 番目と同じように正常に推論されれば完了です。

索引モデルが issue の本文から書いたものです。

評価

技術スタック
typescript
領域
compilers
issue の種類
バグ
難易度
5/5
見積もり時間
1週間以上
活発さ
停滞
明瞭さ
おおむね明確
初心者へのやさしさ
35/100

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

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