microsoft / microsoft/TypeScript
Member-wise checks give incorrect errors for type assertions
オープン
まだ誰も着手していません。
In Discussion
Needs Investigation
Rescheduled
Suggestion
- 主要言語
- Go
- スター
- 111k
- フォーク
- 14.4k
- 平均マージ
- 1日 19時間
- マージ済み PR(30日)
- 117
説明
// No error. ✅
let okay = { id: 123, blah: "extra" } as { id: number };
// Errors. ❌
let waat = [{ id: 123, blah: "extra" }] as { id: number }[];
// ~~~~
// Conversion of type '{ id: number; blah: string; }[]' to type '{ id: number; }[]' may be a mistake because neither type sufficiently overlaps with the other. If this was intentional, convert the expression to 'unknown' first.
// Type '{ id: number; blah: string; }' is not comparable to type '{ id: number; }'.
// Object literal may only specify known properties, and 'blah' does not exist in type '{ id: number; }'.
Expected: Both of these type assertions should consistently apply the appropriate relationship check, and both should be free of errors.
Actual: The first assertion is free of errors, while the second has an excess property error.
Similar example I found over at https://github.com/microsoft/TypeScript/pull/55152/files#r1275497478:
let okay = { foo: "" } as { id: 123 };
// ~~~~~~~~~~~~~~~~~~~~~~~~~~
// Conversion of type '{ foo: string; }' to type '{ id: 123; }' may be a mistake because neither type sufficiently overlaps with the other. If this was intentional, convert the expression to 'unknown' first.
// Property 'id' is missing in type '{ foo: string; }' but required in type '{ id: 123; }'.
let waat = [{ foo: "" }] as { id: 123 }[];
// ~~~
// Conversion of type '{ foo: string; }[]' to type '{ id: 123; }[]' may be a mistake because neither type sufficiently overlaps with the other. If this was intentional, convert the expression to 'unknown' first.
// Type '{ foo: string; }' is not comparable to type '{ id: 123; }'.
// Object literal may only specify known properties, and 'foo' does not exist in type '{ id: 123; }'.
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
調査の方向性
リンクされた TypeScript Playground の再現から始め、PR #55152 にある類似の例も含めて、2 つの型アサーションを比較します。配列アサーションに使用されているメンバー単位の関係チェックを追跡し、報告されたケースの回帰テストを追加します。完了条件は、両方のアサーションが誤った excess-property エラーを一貫して回避することです。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- typescript
- 領域
- compilers
- issue の種類
- バグ
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 活発さ
- 停滞
- 明瞭さ
- 明確に書かれている
- 初心者へのやさしさ
- 45/100