microsoft / microsoft/TypeScript

TypeScript not enforcing the return type of optional methods defined in interfaces implemented by parents of classes

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

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

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

説明

TypeScript Version: 3.5.0 (Also tried 3.4.1, 3.0.1, and 2.4.1)

Search Terms: Inheritance, interface, return type, parent, child, override, overload, abstract, optional method, optional interface, implements, extends

Code

interface Mx {
  aMethod?(): number;
}

abstract class Base implements Mx {

}

class Child extends Base {
  public aMethod() {
    return 'hello world';
  }
}

Expected behavior:
TypeScript tells me that the return type for Child#aMethod is wrong.

This behaviour is achieved if I add implements Mx on the Child class.

Actual behavior:
TypeScript tells me nothing! It feels that Child#aMethod is well within its rights to return a string.

Playground Link: linky!

Related Issues: I didn't really find any similar looking issues?

The result is this could maybe relate to #22815

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

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

はじめの一歩

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

調査の方向性

まず、リンクされた TypeScript Playground の例を再現し、次に Child が Mx を明示的に実装しているバージョンと比較します。TypeScript が冗長な implements 句を要求せずに、Child#aMethod の互換性のない string 戻り値の型を報告すれば、作業は完了です。

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

評価

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

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

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