microsoft / microsoft/TypeScript
RegExpIndicesArray - Named group indices can be undefined
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
RegExpIndicesArray, Regex indices
### 🕗 Version & Regression Information
- This is the behaviour in every version I tried, and I reviewed the FAQ for entries about Regular Expressions
### ⏯ Playground Link
https://www.typescriptlang.org/play/?target=9&ts=6.0.0-dev.20260322#code/PTAEGcCcGNgWwIYEsB2A6ALuAUN6B7FcDUAc0nwFcAHUAXlGAQAoB+AHjiQBMA+AIwCUrWNzQBTAB7jozAOQJocwQEI0qbkmjjwa8lWq6A2gCIu3EwF0A3LgJESGqfTIUaRgAw3sQA
### 💻 Code
```ts
const group = /a(?b)?c/d.exec('ac')!.indices!.groups!["mid"];
const index = group[0];
```
The typing assumes that group indices are of type `[number, number]`, but these can also be `undefined`
### 🙁 Actual behavior
`typeof group === "undefined"`
hence, the type system should have complained when attempting to access via index.
### 🙂 Expected behavior
`'group' is possibly 'undefined'`
...should be reported by the type system.
### Additional information about the issue
https://github.com/microsoft/TypeScript/pull/61079 fixed the same issue for the outer `RegExpIndicesArray` itself, but not the indices array on the matched groups
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 ví dụ Playground được liên kết và so sánh kiểu của các chỉ số nhóm với thay đổi RegExpIndicesArray bên ngoài trong pull request #61079. Công việc được hoàn thành khi TypeScript báo cáo rằng chỉ số của nhóm được đặt tên có thể là undefined đối với đoạn mã được minh họa, đồng thời vẫn duy trì kiểu hợp lệ cho các nhóm đã tham gia vào match.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Đánh giá
- Công nghệ
- javascript, 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
- Đặc tả rõ ràng
- Mức phù hợp với người mới
- 68/100