microsoft / microsoft/TypeScript
Proposal: Follow program flow in constructor when strictPropertyInitialization = true
まだ誰も着手していません。
- 主要言語
- Go
- スター
- 111k
- フォーク
- 14.3k
- 平均マージ
- 2日 4時間
- マージ済み PR(30日)
- 132
説明
Search Terms
constructor strictPropertyInitialization flow
Suggestion
TypeScript should follow unconditional function calls in constructor when checking for strict property initialization.
Use Cases
It is a common pattern to be able to reset objects after construction and, thus, to transfer object initialization to a separate routine:
class C
{
private p: number;
public constructor() { Initialize() }
public Initialize() { p = 0; }
}
Currently, TypeScript doesn't consider functions being unconditionally called from within a constructor function when checking for strict property initialization. The above code yields a compiler error.
I propose TypeScript to be able to analyse code flow and recognize property initialization that's performed in functions unconditionally called by the constructor function.
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, etc.)
- This feature would agree with the rest of TypeScript's Design Goals.
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
調査の方向性
まず、コンストラクターと無条件の関数呼び出しに対するコンパイラーの strictPropertyInitialization チェックを追跡してください。issue にはファイルもテストも記載されていません。別途定義された Initialize メソッドを通る制御フローがプロパティの初期化にどのような影響を与えるべきかを判断し、そのうえで、例が受け入れられる一方、無条件でない呼び出しは引き続き拒否されることを示すカバレッジを追加してください。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- typescript
- 領域
- compilers
- issue の種類
- 機能追加
- 難易度
- 5/5
- 見積もり時間
- 1週間以上
- 活発さ
- 停滞
- 明瞭さ
- おおむね明確
- 初心者へのやさしさ
- 25/100