microsoft / microsoft/TypeScript

Argument of type 'this' is not assignable to parameter of type 'NonNullable'?

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

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

Effort: Difficult Experimentation Needed Help Wanted Suggestion
主要言語
Go
スター
111k
フォーク
14.3k
平均マージ
2日 4時間
マージ済み PR(30日)
132

説明

TypeScript Version: 4.0.3

Search Terms: 'this' is not assignable to 'NonNullable'

Code

abstract class TreeNode {
  parent: this | null = null; // polymorph this
  left: this | null = null;
  right: this | null = null;

  replaceChild(child: this, replacement: this | null = null) { // this - polymorph type
    this.left = child;
    this.right = replacement;
  }

  removeNode() {
    this.parent?.replaceChild(this, null); // ERROR
  }

  removeNode2Way() {
    if (this.parent) {
      this.parent.replaceChild(this, null); // OK
    }
  }
}

Expected behavior:
Conditional call without errors.

Actual behavior:
Error: Argument of type 'this' is not assignable to parameter of type 'NonNullable'

Playground Link: Playground

Related Issues:

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

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

はじめの一歩

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

調査の方向性

TypeScript 4.0.3 の playground の再現から始め、removeNode の条件付き呼び出しと removeNode2Way のガード付き呼び出しを比較します。polymorphic this とオプショナル呼び出しの型チェックの経路を追跡します。条件付き呼び出しが、ガード付きの形式を後退させることなく受け入れられれば完了です。

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

評価

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

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

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