microsoft / microsoft/TypeScript
Misleading error message "'{}' and 'number' have no overlap"
まだ誰も着手していません。
- 主要言語
- Go
- スター
- 111k
- フォーク
- 14.4k
- 平均マージ
- 1日 19時間
- マージ済み PR(30日)
- 117
説明
🔎 Search Terms
empty object type, unintentional comparison
🕗 Version & Regression Information
- This is the behavior in every version I tried, and I reviewed the FAQ for entries about object types and structural typing
⏯ Playground Link
💻 Code
if ({} === 0) {}
🙁 Actual behavior
TS 2367: "This comparison appears to be unintentional because the types '{}' and 'number' have no overlap."
🙂 Expected behavior
TS 2367: "This comparison appears to be unintentional because the types 'object' and 'number' have no overlap."
Additional information about the issue
the type {} and number do have overlap; number is a subset of {}.
declare const n: number;
// allowed!
const emptyObjectType: {} = n;
TS is correct to report an error, but it should give a technically correct reason for the error.
Analogous (very contrived) examples can be made for similar coincidentally-including-primitive types, like
// This comparison appears to be unintentional because the types '{ toFixed(): string; toPrecision(): string; }' and 'number' have no overlap.
if ({ toFixed(): string { return "" }; toPrecision(): string { return "" }} === 0) {}
// yet this is allowed
const numbery: { toFixed(): string; toPrecision(): string; } = 0;
Stems from discord discussion beginning here: https://discord.com/channels/508357248330760243/508357638677856287/1310419206260654081
Closely related to discussion regarding https://github.com/microsoft/TypeScript/issues/60582
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
調査の方向性
まず、リンクされた TypeScript Playground の再現コードを実行し、診断 TS2367 を追跡します。報告された '{}' と 'number' という文言を、期待される 'object' と 'number' という文言と比較し、次に、示されている比較のカバレッジを追加または更新して、関連する例でも診断が正しいままであることを確認します。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- typescript
- 領域
- compilers
- issue の種類
- バグ
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 活発さ
- 停滞
- 明瞭さ
- おおむね明確
- 初心者へのやさしさ
- 45/100