microsoft / microsoft/TypeScript
abstract type guard does not narrow when keyed with a unique symbol
Chưa có ai nhận issue này.
- Ngôn ngữ chính
- Go
- Star
- 111k
- Fork
- 14.3k
- Merge trung bình
- 2 ngày 4 giờ
- Pull request đã merge (30 ngày)
- 132
Mô tả
### 🔎 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_
Hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Hướng nghiên cứu
Bắt đầu với TypeScript Playground được liên kết và tái hiện sự khác biệt giữa lệnh gọi unique-symbol và lệnh gọi có tên isBar() trong Foo.method(). Theo dõi hành vi thu hẹp kiểu đối với cả hai trình bảo vệ kiểu trừu tượng, sau đó xác minh rằng lệnh gọi dựa trên khóa symbol thu hẹp this thành Bar và không còn báo lỗi barMethod nữa.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Đánh giá
- Công nghệ
- typescript
- Lĩnh vực
- compilers
- Loại issue
- Lỗi
- Độ khó
- 4/5
- Thời gian dự kiến
- 3-5 ngày
- Mức độ hoạt động
- Đình trệ
- Độ rõ ràng
- Khá rõ ràng
- Mức phù hợp với người mới
- 42/100