microsoft / microsoft/TypeScript
Confusing error when destructuring and overwriting with a wrong type
まだ誰も着手していません。
- 主要言語
- Go
- スター
- 111k
- フォーク
- 14.4k
- 平均マージ
- 1日 19時間
- マージ済み PR(30日)
- 117
説明
Bug Report
I noticed it because I put the spread at the bottom instead of top, but I had a hard time finding my mistake because of this. It's easy to spot if the object is small like in this example, but in my case the error and the spread was separated by multiple lines. Any other suggested error would be much clearer, but this confused me very much.
🔎 Search Terms
destructuring, spread, error reporting
🕗 Version & Regression Information
- This is the behavior in every version I tried, and I reviewed the FAQ for entries about destructuring, spread, error reporting
⏯ Playground Link
Playground link with relevant code
💻 Code
interface Test {
foo: boolean;
}
interface LesserTest {
foo?: boolean | null;
}
const bar: LesserTest = {
foo: null
}
const barWrong: Test = {
foo: true, // Type 'boolean | null' is not assignable to type 'boolean'.
...bar
}
// Type '{ foo?: boolean | null | undefined; }' is not assignable to type 'Test'. - such error would be much better
const barRight: Test = {
...bar
}
🙁 Actual behavior
The same property will be overwritten with a wrong type, but the error is reported in a wrong place, where the type is correct.
🙂 Expected behavior
The error should be reported on the destructured variable where the type is wrong or in the main variable barWrong.
I also noticed that if those types would match we get an error 'foo' is specified more than once, so this usage will be overwritten. which is also much better.
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
調査の方向性
リンクされた TypeScript Playground の例から始め、barRight と比較しながら barWrong の診断を再現してください。object spread と上書きされたプロパティに対する checker のパスを追跡してください。診断が型の誤ったプロパティまたは barWrong を指し、結果として生じる型の不一致を明確に説明すれば完了です。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- typescript
- 領域
- compilers
- issue の種類
- バグ
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 活発さ
- 停滞
- 明瞭さ
- おおむね明確
- 初心者へのやさしさ
- 35/100