microsoft / microsoft/TypeScript

abstract type guard does not narrow when keyed with a unique symbol

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

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

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

説明

### 🔎 Search Terms

abstract type guard symbol

### 🕗 Version & Regression Information

- This is the behavior in every version I tried, and I reviewed the FAQ for entries about abstract type guard

### ⏯ Playground Link

https://www.typescriptlang.org/play/?ts=6.0.0-dev.20250810&ssl=28&ssc=2&pln=1&pc=1#code/FAYw9gdgzgLgBASygIQIYCc4F44GUCeAtgEZgA2AFAERJrpUCUA3MMKsbOqiPCGalChwAYmDBwA3sDgy47Tt3i0MFBgC44MABZJEQui1lyOMLjzgBtZegC6qjdt26DrI4QCm2sABN7cAG5gCN6S0kayCABmcBSOUFYoGHYMDKHh6XAA9JlwACo6QlBaYACuZCEQYPDE7nIQcO7o6GDoYRmycQB0xBgAsp7Fvsxt4QC+DWRQtVExXdaqqVLtRl096P1eQ4YZoyO7u6D8gnB0DQAeMO4Q3kKi4kuyYP6N6MHTieh+cXonGGkZ6E8JXQ9VMJXc2xkByMTxeb0s1mSDgKP1OD3SgJgwNB6HBkLg0Nkaw2gz8gWCkn2QA

### 💻 Code

```ts
const isBar = Symbol("isBar");

abstract class Foo {
abstract isBar(): this is Bar;
abstract [isBar](): this is Bar;

method(): void {
if (this[isBar]()) {
// This should not be an error, it should work the same as .isBar()
this.barMethod();
} else if (this.isBar()) {
this.barMethod();
}
}
}

class Bar extends Foo {
override isBar(): this is Bar {
return true;
}

override [isBar](): this is Bar {
return true;
}

barMethod(): void {}
}
```

### 🙁 Actual behavior

TS reports an error:

> `Property 'barMethod' does not exist on type 'Foo'. Did you mean 'method'?(2551)`

### 🙂 Expected behavior

No error should happen here, the type guard should work the same as the non-symbol version of the method.

### Additional information about the issue

_No response_

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

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

はじめの一歩

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

調査の方向性

リンクされた TypeScript Playground から始め、Foo.method() 内の unique-symbol 呼び出しと名前付き isBar() 呼び出しの違いを再現します。両方の抽象型ガードについて型の絞り込みの挙動を追跡し、シンボルキーによる呼び出しによって this が Bar に絞り込まれ、barMethod エラーが報告されなくなることを確認します。

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

評価

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

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

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