microsoft / microsoft/TypeScript
Allow primitive LHS to `instanceof` operator if RHS is a custom `hasInstance`
- 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
in:title instanceof
### 🕗 Version & Regression Information
- This changed between versions 5.2 and 5.3
- This changed in commit or PR #55052
### ⏯ Playground Link
https://www.typescriptlang.org/play/?#code/IwAglgdgzgLghhAxgUwPYDMQG8QG0DKAngLYBGqANgHQAWcUAktPEsgLoAUAlNiAE7IYAVz4QQMPkOQgAvjICwAKAD0ykAD0QAFRrSKydDAC0dCABMQUMGekYQCEAHJIsBCgyOQyAB4AHAVBWqGLEQrAgpLaYMIS+0o4IhI4ANPZiqKQAVsiIMOKxtnz2+XEgvnB8cMSCyHxUHABMAMwArAAcXEA
### 💻 Code
```ts
1 instanceof { [Symbol.hasInstance]() { return true }}
```
### 🙁 Actual behavior
Error: The left-hand side of an 'instanceof' expression must be of type 'any', an object type or a type parameter.(2358)
### 🙂 Expected behavior
No errors
### Additional information about the issue
For custom 'Symbol.hasInstance' methods, `number instanceof obj` can return true or false according to implementation.
Hướng dẫn đóng góp
Hướng nghiên cứu
Bắt đầu với bản tái hiện TypeScript Playground được liên kết và so sánh hành vi được báo cáo đối với `1 instanceof { [Symbol.hasInstance]() { return true }}` với kết quả mong đợi. Truy vết đường đi kiểm tra kiểu cho các biểu thức `instanceof`, sau đó thêm coverage cho thấy một vế trái kiểu primitive được chấp nhận khi vế phải định nghĩa `Symbol.hasInstance` tùy chỉnh.
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ó
- 3/5
- Thời gian dự kiến
- 1-2 ngày
- Mức độ hoạt động
- Ít trao đổi
- Độ rõ ràng
- Khá rõ ràng
- Mức phù hợp với người mới
- 58/100