microsoft / microsoft/TypeScript
RegExpIndicesArray - Named group indices can be undefined
还没有人认领这个 Issue。
- 主要语言
- Go
- 星标
- 111k
- 派生
- 14.3k
- 平均合并
- 2 天 4 小时
- 30 天内合并 PR
- 132
描述
### 🔎 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
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
调研方向
从链接的 Playground 示例开始,将组索引的类型与 pull request #61079 中外部 RegExpIndicesArray 的更改进行比较。当 TypeScript 针对所示代码报告命名组的索引可能为 undefined,同时保留已参与匹配的组的有效类型时,工作就完成了。
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- javascript, typescript
- 领域
- compilers
- Issue 类型
- 缺陷
- 难度
- 3/5
- 预计耗时
- 1-2 天
- 活跃度
- 冷清
- 描述清晰度
- 描述清楚
- 新手友好度
- 68/100