microsoft / microsoft/TypeScript
Make Arrays in public API readonly
まだ誰も着手していません。
- 主要言語
- Go
- スター
- 111k
- フォーク
- 14.4k
- 平均マージ
- 1日 19時間
- マージ済み PR(30日)
- 117
説明
Suggestion
🔍 Search Terms
API readonly
getchildren readonly
✅ Viability Checklist
My suggestion meets these guidelines:
- This wouldn't be a breaking change in existing TypeScript/JavaScript code
- This wouldn't change the runtime behavior of existing JavaScript code
- This could be implemented without emitting different JS based on the types of the expressions
- This isn't a runtime feature (e.g. library functionality, non-ECMAScript syntax with JavaScript output, new syntax sugar for JS, etc.)
- This feature would agree with the rest of TypeScript's Design Goals.
This might actually break users of TypeScript's API. But so did the last change to make all properties on Node readonly.
Ideally users only need to adjust their types or create a slice of the array.
⭐ Suggestion
Node#getChildren() should return a readonly Node[].
UnionOrIntersectionType#types should be readonly Type[]
TypeChecker#getBaseTypes(type) should return readonly BaseType[] | undefined
TypeChecker#getPropertiesOfType(type) should return readonly Symbol[]
Symbol#declarations should be readonly Declaration[], well actually it should be readonly Declaration[] | undefined, but that's a different long-standing issue
... just to name a few. There are more throughout the API.
probably a stretch goal: make every property on Type, Symbol, etc. readonly (for API users)
📃 Motivating Example
The current types allow API users to mutate data structures they shouldn't be mutating. This might cause severe misbehavior down the road. E.g. EndOfFileToken#getChildren() might return emptyArray. If I modify this array, everything will break, because TypeScript reuses this array instance literally everywhere.
On a related note: It might make sense to change to const emptyArray: readonly never[]. Though that will probably cause a few (reasonable) breaks in the compiler itself.
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
調査の方向性
まず、Node#getChildren、UnionOrIntersectionType#types、TypeChecker#getBaseTypes、TypeChecker#getPropertiesOfType、Symbol#declarations の public API 宣言を読みます。ほかの public な配列プロパティを検索し、emptyArray の使用箇所を確認します。対象となる公開配列が readonly になっていて、実行時の JavaScript の動作が変わっていなければ完了です。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- typescript
- 領域
- api, compilers
- issue の種類
- 機能追加
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 活発さ
- 停滞
- 明瞭さ
- おおむね明確
- 初心者へのやさしさ
- 35/100