microsoft / microsoft/TypeScript
Experiment with always using parameters from base types for derived methods
オープン
まだ誰も着手していません。
In Discussion
Suggestion
- 主要言語
- Go
- スター
- 111k
- フォーク
- 14.3k
- 平均マージ
- 1日 19時間
- マージ済み PR(30日)
- 117
説明
Note some related issues for doing this with properties rather than methods: #3667, #6118, #1373.
Goal
We want to make it easier for users to derive types without rewriting the same parameter signature every time
class Base {
method(x: number) {
// ...
}
}
class Derived extends Base {
method(x) {
// 'x' should have the type 'number' here.
}
}
Potential ideas
- Only enable in
noImplicitAny(doesn't work for default initializers 😞) - Revert to
anyin all locations, opt in with another strictness flag (😞) - Something else? 😕
Potential issues
Default initializers with more capable derived types
class A {
a = 1;
}
class B extends A {
b = 2;
}
class Base {
method(x: A) {
// ...
}
}
class Derived extends Base {
method(x = new B) {
x.b;
// Today, 'x' has type 'B' which is technically unsound
// but that's just what we do. Does changing this to 'A' break things?
}
}
Default initializers that become less-capable via contextual types
class Base {
method(x: "a" | "b") {
// ...
}
}
class Derived extends Base {
method(x = "a") {
// We have to make sure 'x' doesn't have type '"a"'
// which is both unsound and less useful.
}
}
Distinction between properties and methods
Would this work?
class Base {
method = (x: number) => {
// ...
}
}
class Derived extends Base {
method(x) {
// Does 'x' have the type 'number' here?
}
}
What about this?
class Base {
method(x: number) {
// ...
}
}
class Derived extends Base {
method = (x) => {
// Does 'x' have the type 'number' here?
}
}
Keywords: base type derived contextual contextually inherit methods implicit any
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
調査の方向性
この issue の目的と例から始め、その後、関連するプロパティの issue #3667、#6118、#1373 と比較してください。派生メソッド、デフォルト初期化子、メソッドプロパティをどのように文脈化すべきかを調査してください。完了とは、すべての例について動作と strictness への影響が解決されていることを意味します。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- typescript
- 領域
- compilers
- issue の種類
- 機能追加
- 難易度
- 5/5
- 見積もり時間
- 1週間以上
- 活発さ
- 停滞
- 明瞭さ
- 説明が足りない
- 初心者へのやさしさ
- 25/100