microsoft / microsoft/TypeScript

Intersection, Union depends on type variable instantiation order

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

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

In Discussion Suggestion
主要言語
Go
スター
111k
フォーク
14.4k
平均マージ
1日 19時間
マージ済み PR(30日)
117

説明

🔎 Search Terms

generic type variable intersection union order

🕗 Version & Regression Information
  • This is the behavior in every version I tried, and I reviewed the FAQ for entries about Generics
⏯ Playground Link

Workbench Repro

💻 Code
type Union<A, B> = A | B
type UnionAny<T> = Union<T, any>
type UnionUnknown<T> = Union<unknown, T>

// these should all be the same type but are respectively: any, any, unknown 
type UA0 = Union<unknown, any>
//   ^?
type UA1 = UnionAny<unknown>
//   ^?
type UA2 = UnionUnknown<any>
//   ^?

type Intersect<A, B> = A & B
type IntersectAny<T> = Intersect<T, any>
type IntersectNever<T> = Intersect<never, T>

// these should all be the same type but are respectively: never, any, never
type AN0 = Intersect<never, any>
//   ^?
type AN1 = IntersectAny<never>
//   ^?
type AN2 = IntersectNever<any>
//   ^?

🙁 Actual behavior

The types UA0, UA1 are resolved as any and UA2 is resolved as unknown. These all map down to the same union of unknown and any, so should all be the same type.

The types AN0, AN2 are resolved as never and AN1 resolved as any. These all map down to be the intersection of any and never, so should all be the same type.

🙂 Expected behavior

I expect UA0, UA1 and UA2 to resolve as the same type (probably any, but preferably unknown)
I expect AN0, AN1 and AN2 to resolve as the same type (probably never)

Additional information about the issue

No response

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

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

はじめの一歩

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

調査の方向性

Workbench Repro から始め、UA0、UA1、UA2、AN0、AN1、AN2 の解決された型を比較します。ジェネリックのインスタンス化、ユニオン、インターセクションに対する type-checker の動作を追跡します。同値な式が一貫して解決され、repro の期待される型が成立すれば完了です。

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

評価

技術スタック
typescript
領域
compilers
issue の種類
バグ
難易度
5/5
見積もり時間
1週間以上
活発さ
停滞
明瞭さ
明確に書かれている
初心者へのやさしさ
30/100

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

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