microsoft / microsoft/TypeScript
Type cast should try to remove readonly modifier
オープン
まだ誰も着手していません。
Awaiting More Feedback
Suggestion
- 主要言語
- Go
- スター
- 111k
- フォーク
- 14.3k
- 平均マージ
- 1日 19時間
- マージ済み PR(30日)
- 117
説明
The compiler should try to use mutable versions of readonly tuples when couldn't cast readonly tuples to mutable arrays mainly for usability of as const. The performance impact of this would be a little because the condition when this check runs is limited.
TypeScript Version: 3.7.x-dev.20200123
Search Terms:
Code
([0] as [0]) as number[];
([0] as [0]) as readonly number[];
// As the expansion of [0] as const
([0] as readonly [0]) as number[]; // error
([0] as readonly [0]) as readonly number[];
Expected behavior:
pass
Actual behavior:
Conversion of type 'readonly [0]' to type 'number[]' may be a mistake because neither type sufficiently overlaps with the other. If this was intentional, convert the expression to 'unknown' first.
The type 'readonly [0]' is 'readonly' and cannot be assigned to the mutable type 'number[]'.(2352)
Related Issues:
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
調査の方向性
まず、TypeScript Playground または TypeScript 3.7.x-dev.20200123 を使って readonly タプルのキャスト例を再現し、次にコンパイラーの insufficient-overlap と readonly の代入可能性に関するチェックを追跡します。readonly タプルから number[] へのキャストが、中間の unknown キャストを必要とせず期待どおりに通過し、既存の安全性チェックが維持されていれば完了です。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- typescript
- 領域
- compilers
- issue の種類
- バグ
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 活発さ
- 停滞
- 明瞭さ
- 明確に書かれている
- 初心者へのやさしさ
- 35/100