microsoft / microsoft/TypeScript

Generics in union should be inferred as `never` when possible

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

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

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

説明

🔎 Search Terms

generics, inference, union, never

🕗 Version & Regression Information

This is the behavior in every version I tried, and I reviewed the FAQ for entries about union and never.

⏯ Playground Link

https://www.typescriptlang.org/play/?#code/MYewdgzgLgBAZjAvDAPAFQDQD4AUAPALhjRgB8ZoAnASzAHMMYBPIk8sAVwFsAjAU0oBKJFmYAoODgDkAQymMAjMIgyo1CHGp8IMTrwEwA9IeIx1MAEQyLukAHcxY0JFh0kqEnzxQ+YACY6HP58mmB8friEpuzc-EIiMHhidDhKFKrqmtq6sQbGpuZBfiG04bZ2QA

💻 Code
const f = <T,>(x: T | string, y: T | number) => y
f('a', 1) satisfies number // T is "a" now

const g = <T extends undefined>(x: T | number) => x
g(1) satisfies number // T is undefined now
🙁 Actual behavior

T is not never.

🙂 Expected behavior

T should be inferred as never, because it can be anything.

Additional information about the issue

This may be related to #42491.

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

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

はじめの一歩

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

調査の方向性

リンク先の TypeScript Playground の再現から始め、関連する issue #42491 とジェネリック推論の挙動を比較してください。両方の例で T が never として推論され、satisfies チェックが期待どおりの結果を生成すれば、作業は完了です。

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

評価

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

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

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