microsoft / microsoft/TypeScript

Distribute property type union members to create union of object types

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

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

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

説明

TypeScript Version: v3.9.0-dev.20200222

Search Terms: union type object property

Code

type Test =
  | { b: [false, "a"] }
  | { b: [true, "b"] }
  
declare const b2: boolean;
const a: Test = { b: b2 ? [b2, "b"] : [b2, "a"] }

Expected behavior:
No error. I'm not exactly sure if this is a bug or feature request but, essentially, it'd be nice if TS could recognize that: { b: [true, "b"] | [false, "a"]; } is identical to { b: [true, "b"] } | { b: [false, "a"]; }

Actual behavior:

Type '{ b: [true, "b"] | [false, "a"]; }' is not assignable to type 'Test'.
  Type '{ b: [true, "b"] | [false, "a"]; }' is not assignable to type '{ b: [true, "b"]; }'.
    Types of property 'b' are incompatible.
      Type '[true, "b"] | [false, "a"]' is not assignable to type '[true, "b"]'.
        Type '[false, "a"]' is not assignable to type '[true, "b"]'.
          Type 'false' is not assignable to type 'true'.

Playground Link: Playground Link

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

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

はじめの一歩

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

調査の方向性

まず、リンクされた Playground で issue の TypeScript コードサンプルにある代入を再現し、報告された診断と期待される動作を比較します。タプルとオブジェクトの互換性のない union に対する正しいチェックを維持したまま、例が受け入れられれば完了です。issue ではソースファイルもテストパスも特定されていません。

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

評価

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

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

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