microsoft / microsoft/TypeScript

Subclass method is not allowed (TS2425) if the parent class has a property of type any with the same name

オープン
#27,965 コメント 19 件 リアクション 13 件 担当者 0 名 GitHub で見る

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

Awaiting More Feedback Suggestion
主要言語
Go
スター
111k
フォーク
14.4k
平均マージ
1日 19時間
マージ済み PR(30日)
117

説明

TypeScript appears to treat class methods as something fundamentally different from a class prototype property of type function. This is not in agreement with the standard semantics of ES6.

TypeScript Version: all versions, as far as I have been able to test.

Search Terms: method member property any parent class subclass

Code

class Super {
    prop: any;
}

class Derived extends Super {
    prop() {}
}

Expected behavior: should compile without a problem. Note that by the ES6 standard, the above definition of Derived is equivalent to the following, which TypeScript compiles without a problem:

class Derived extends Super {}

Derived.prototype.prop = function(){};

Actual behavior:

Error TS2425: Class 'Super' defines instance member property 'prop', but extended class 'Derived' defines it as instance member function.

Playground Link: https://www.typescriptlang.org/play/#src=class%20Super%20%7B%0D%0A%20%20%20%20prop%3A%20any%3B%0D%0A%7D%0D%0A%0D%0Aclass%20Derived%20extends%20Super%20%7B%0D%0A%20%20%20%20prop()%20%7B%7D%0D%0A%7D%0D%0A

Related Issues: I didn't find similar issues, although I started by looking for issues requesting for the ability to disable particular errors (TS2425 in this case). There are several (closed) issues in which such an ability is requested or suggested, but I believe the proper solution would be to bring TypeScript in agreement with ES6. After all, it claims to be a superset!

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

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

はじめの一歩

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

調査の方向性

リンク先の TypeScript Playground で例を再現することから始め、型が any の継承されたプロパティとサブクラスのメソッドとの比較に対して TS2425 を報告するチェックを追跡します。これを issue で説明されている同等のプロトタイプ代入と比較します。クラス定義が TS2425 なしでコンパイルされ、関連する継承チェックが引き続き維持されていれば完了です。

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

評価

技術スタック
typescript
領域
compilers
issue の種類
バグ
難易度
4/5
見積もり時間
3〜5日
活発さ
停滞
明瞭さ
明確に書かれている
初心者へのやさしさ
35/100

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

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