microsoft / microsoft/TypeScript
RegExpIndicesArray - Named group indices can be undefined
まだ誰も着手していません。
- 主要言語
- Go
- スター
- 111k
- フォーク
- 14.3k
- 平均マージ
- 2日 4時間
- マージ済み PR(30日)
- 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 にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
調査の方向性
リンクされている Playground の例から始め、グループインデックスの型付けを、pull request #61079 における外側の RegExpIndicesArray の変更と比較します。示されているコードについて、名前付きグループのインデックスが undefined になる可能性があると TypeScript が報告し、同時にマッチに参加したグループについて有効な型付けが維持されれば、作業は完了です。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- javascript, typescript
- 領域
- compilers
- issue の種類
- バグ
- 難易度
- 3/5
- 見積もり時間
- 1〜2日
- 活発さ
- 静か
- 明瞭さ
- 明確に書かれている
- 初心者へのやさしさ
- 68/100