microsoft / microsoft/TypeScript
Type parameter not usable as type argument in identical type; union in constraint becomes intersection
まだ誰も着手していません。
- 主要言語
- Go
- スター
- 111k
- フォーク
- 14.3k
- 平均マージ
- 2日 4時間
- マージ済み PR(30日)
- 132
説明
🔎 Search Terms
indexed access, constraints, generic, unions, ts2344
🕗 Version & Regression Information
- This changed between versions 3.3 and 3.5 (likely #30769)
⏯ Playground Link
💻 Code
interface Foo<T extends { x: string }, U extends (T | { x: "a" })['x']> {
z: Foo<T, U> // error!
// ~ Type 'U' does not satisfy the constraint 'T["x"] & "a"'. 🙃
}
🙁 Actual behavior
The U type parameter is rejected as a type argument with a TS2344 error about how it doesn't satisfy the constraint. The constraint seems to have shifted from a union to an intersection, even though it comes from an identical place.
🙂 Expected behavior
The U type parameter should be accepted as a type argument.
Additional information about the issue
Distilled from SO question.
I expect this is a consequence of #30769 as per https://github.com/microsoft/TypeScript/issues/31731#issuecomment-498465358, but it is at least somewhat surprising that this should happen when the types involved are identical. One could rewrite the constraint to U extends T["x"] | "a", of course, but this is distilled from the above SO question which is presumably distilled from some use case. What's happening here, exactly, and is it intended, a design limitation, or a bona fide bug?
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
調査の方向性
リンクされた TypeScript Playground と、issue にある最小限のジェネリック制約の例から始めてください。報告されているバージョン 3.3 と 3.5 の間のリグレッション、および関連する issue #30769 を考慮し、インデックスアクセス制約が期待されるユニオンではなくインターセクションとして扱われる理由を調査してください。U が TS2344 なしで受け入れられるように、この動作が意図されたものかどうかを判断するか、動作を修正できれば完了です。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- typescript
- 領域
- compilers
- issue の種類
- バグ
- 難易度
- 5/5
- 見積もり時間
- 1週間以上
- 活発さ
- 停滞
- 明瞭さ
- おおむね明確
- 初心者へのやさしさ
- 35/100