microsoft / microsoft/TypeScript

T.constructor should be of type T

オープン
#3,841 コメント 103 件 リアクション 291 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

In Discussion Suggestion
主要言語
Go
スター
111k
フォーク
14.3k
平均マージ
2日 4時間
マージ済み PR(30日)
132

説明

Given

``` typescript
class Example {
}
```

The current type of `Example.constructor` is `Function`, but I feel that it should be `typeof Example` instead. The use case for this is as follows:

I'd like to reference the current value of an overridden static property on the current class.

In TypeScript v1.5-beta, doing this requires:

``` typescript
class Example {
static someProperty = "Hello, world!";

constructor() {
// Output overloaded value of someProperty, if it is overloaded.
console.log(
(this.constructor).someProperty
);
}
}

class SubExample {
static someProperty = "Overloaded! Hello world!";

someMethod() {
console.log(
(this.constructor).someProperty
);
}
}
```

After this proposal, the above block could be shortened to:

``` typescript
class Example {
static someProperty = "Hello, world!";

constructor() {
// Output overloaded value of someProperty, if it is overloaded.
console.log(
this.constructor.someProperty
);
}
}

class SubExample {
static someProperty = "Overloaded! Hello world!";

someMethod() {
console.log(
this.constructor.someProperty
);
}
}
```

This removes a cast to the current class.

コントリビューションガイド

コントリビューションガイドを開く

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

調査の方向性

Use the two class examples in the issue as the behavioral starting point, then trace the TypeScript type-checking rules for instance constructors and static members. Done means the proposed this.constructor accesses type-check without the casts shown, while preserving the intended behavior for subclasses.

索引モデルが issue の本文から書いたものです。

評価

技術スタック
typescript
領域
compilers
issue の種類
機能追加
難易度
5/5
見積もり時間
1週間以上
活発さ
活発
明瞭さ
おおむね明確
初心者へのやさしさ
35/100

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。