microsoft / microsoft/TypeScript
Suggestion: perform excess property checks when spreading an inline object literal
まだ誰も着手していません。
- 主要言語
- Go
- スター
- 111k
- フォーク
- 14.3k
- 平均マージ
- 2日 4時間
- マージ済み PR(30日)
- 132
説明
TypeScript Version: 3.9.2
Search Terms:
Code
declare const someCondition: boolean;
type MyObject = { foo: number; bar?: number };
const a: MyObject = {
foo: 1,
bar: 2,
// ✅ Error because `invalid` is an excess property
invalid: 3,
};
const b: MyObject = {
foo: 1,
...(someCondition
? {
bar: 2,
// ❌ `invalid` is an excess property, but we don't get an error here
invalid: 3,
}
: {}),
};
In the example above, I only want to include specific properties when a condition is met. That's the only reason I'm using spread here.
I understand that TypeScript only performs excess property checks inside of object literals. Currently this does not include inline object literals which are being spread inside of another object literal.
In my experience this is a very common code pattern so it would be great if TypeScript handled this.
Expected behavior:
An error
Actual behavior:
No error
Playground Link:
Related Issues:
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
調査の方向性
まず、提供された TypeScript 3.9.2 の例を再現し、オブジェクトリテラルの直接代入と条件付き spread のケースを比較します。spread で使用されるインラインオブジェクトリテラルに対するコンパイラの excess-property checking を調査します。spread のケースで、示されている無効なプロパティがエラーを発生させ、かつ有効な条件付き spread を壊さなければ完了です。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- typescript
- 領域
- compilers
- issue の種類
- 機能追加
- 難易度
- 5/5
- 見積もり時間
- 1週間以上
- 活発さ
- 活発
- 明瞭さ
- おおむね明確
- 初心者へのやさしさ
- 45/100