microsoft / microsoft/TypeScript
keyword to force calling the super on any method
オープン
まだ誰も着手していません。
Awaiting More Feedback
Suggestion
- 主要言語
- Go
- スター
- 111k
- フォーク
- 14.3k
- 平均マージ
- 2日 4時間
- マージ済み PR(30日)
- 132
説明
Today I faced the following code
class A {
// silly warning comment: if you override this, don't forget to call the super method to avoid memory leaks
onExit() {
// do some important cleaning stuff
}
}
class B extends A {
onExit() {
super.onExit(); // good
}
}
class C extends A {
onExit() {
// forgot to call to super.onExit = memory leaks
}
}
The problem is that, unlike a constructor, there is no way to force a method overriding another one to call the parent "super" function.
I wished we had a "concrete"* keyword to let the user know he must call the super method.
class A {
concrete onExit() {
// do some cleaning stuff
}
}
class B extends A {
onExit() {
super.onExit(); // no error
}
}
class C extends A {
// error: Declaration of derived method must contain a 'super' call
onExit() {
}
}
In another language, I could have used the final keyword to prevent overriding the method but then… no overriding allowed neither.
- "concrete" In opposition to "abstract" (for lack of a better name), other ideas: "important" or "mandatory"
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
調査の方向性
この issue では、実装ファイル、テスト、エントリポイントが指定されていません。まず、TypeScript がクラスメソッドをどのようにパースし、継承をチェックし、欠落している super 呼び出しを報告するかを確認してください。完了には、オーバーライドされたメソッドで super 呼び出しを強制するための、合意されたキーワードとセマンティクスが必要です。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- typescript
- 領域
- compilers
- issue の種類
- 機能追加
- 難易度
- 5/5
- 見積もり時間
- 1週間以上
- 活発さ
- 停滞
- 明瞭さ
- おおむね明確
- 初心者へのやさしさ
- 25/100