microsoft / microsoft/TypeScript
exactOptionsPropertyTypes - anomolous behavior with Tuples, options, and spreading.
まだ誰も着手していません。
- 主要言語
- Go
- スター
- 111k
- フォーク
- 14.4k
- 平均マージ
- 1日 19時間
- マージ済み PR(30日)
- 117
説明
Bug Report
🔎 Search Terms
- strictOptionalProperties #43947 #44548
- exactOptionalPropertyTypes
- Labelled Tuple Elements
- Optional Tuple Parameters (enabled with labeling)
- Variadic Tuple Types
🕗 Version & Regression Information
-
Spreading of Variadic Tuple types, as well as the ability to indicate final position optional parameters with labels, were introduced in ts 4.0. The noted behavior has been been present since then.
-
However, although there was hope it would be fixed with 4.4's exact
exactOptionsParameters, it was not.
⏯ Playground Link
💻 Code
type T1 = [x:number, x?:boolean]
const t11:T1 = [1,undefined] // EXCELLENT!! with exactOptionalPropertyTypes:true this became is an error.
const t12:T1 = [1,true]
const t13:T1 = [1]
type T2 = ['^',...T1,'$']
const t21:T2 = ['^',1,true,'$'];
const t22:T2 = ['^',1,undefined,'$']; // noerr - CLAIM - this SHOULD be an error
const t23:T2 = ['^',1,'$']; // err - CLAIM - this SHOULD NOT be an error
🙁 Actual behavior
In the above code, variable declaration for t22 is NOT an err.
In the above code, variable declaration for t23 IS an err.
🙂 Expected behavior
In the above code, variable declaration for t22 IS an err.
In the above code, variable declaration for t23 is NOT an err.
Even though with exactOptionalPropertyTypes , the T1 now no longer considers [number,undefined] to be a legal assignment, when T1 is spread into T2 the old behavior is used instead of the new behavior.
The documentation for exactOptionalPropertyTypes says
In TypeScript 4.4, the new flag --exactOptionalPropertyTypes specifies that optional property types should be interpreted exactly as written, meaning that
| undefinedis not added to the type:
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
調査の方向性
exactOptionalPropertyTypes と T1/T2 のタプル代入を使用する、リンク先の TypeScript Playground の再現から始めてください。variadic tuples が展開されるときにオプショナルなタプル要素がどのように振る舞うかを調査し、その後、既存の T1 チェックが正しいままであることを確認しつつ、t22 が拒否され、t23 が受け入れられることを検証してください。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- typescript
- 領域
- compilers
- issue の種類
- バグ
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 活発さ
- 停滞
- 明瞭さ
- おおむね明確
- 初心者へのやさしさ
- 35/100