microsoft / microsoft/TypeScript

abstract class prototype type has abstract methods even though they are not on the prototype

オープン
#44,181 コメント 1 件 リアクション 0 件 担当者 0 名 GitHub で見る

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

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

説明

Bug Report

🔎 Search Terms

abstract, prototype, type

🕗 Version & Regression Information

All versions I tried

⏯ Playground Link

Playground link with relevant code

💻 Code
abstract class AnAbstract {
  public abstract abstractMethod(): void;

  public nonAbstractMethod(): void {
    // do something
  }
}

// no type error - undefined
console.log(AnAbstract.prototype.abstractMethod);
// no type error - false
console.log(AnAbstract.prototype.hasOwnProperty('abstractMethod'));

// defined
console.log(AnAbstract.prototype.nonAbstractMethod);
// true
console.log(AnAbstract.prototype.hasOwnProperty('nonAbstractMethod'));
🙁 Actual behavior

Abstract class prototype has abstract methods in the type

🙂 Expected behavior

Abstract class prototype to have only concrete methods in the type


I have a function that manually define methods based on what's in the prototype, unfortunately when I use an abstract class the type doesn't reflect reality.

If that type cannot change it would be great to be able to do something like:

type NoAbstract<T> = {
  -abstract [key in keyof T]: T[key];
};

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

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

はじめの一歩

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

調査の方向性

リンクされた TypeScript Playground の例から始め、宣言された抽象メソッドと実行時のプロトタイプの挙動を比較します。抽象クラスのプロトタイプの型がどのように形成されるかを追跡し、具体メソッドは引き続き利用可能である一方、抽象メソッドは利用できないことを確認します。報告された例が実行時の実態と一貫して型チェックされ、関連する回帰テストのカバレッジが通過すれば、issue は完了です。

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

評価

技術スタック
javascript, typescript
領域
compilers
issue の種類
バグ
難易度
4/5
見積もり時間
3〜5日
活発さ
停滞
明瞭さ
おおむね明確
初心者へのやさしさ
35/100

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

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