microsoft / microsoft/TypeScript
RegExpIndicesArray - Named group indices can be undefined
Dieses Issue hat noch niemand übernommen.
- Vorherrschende Sprache
- Go
- Sterne
- 111k
- Forks
- 14.3k
- Ø Merge
- 2 T. 4 Std.
- Gemergte PRs (30 T.)
- 132
Beschreibung
### 🔎 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
Beitragsleitfaden
Erste Schritte
- Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
- Forke das Repository und arbeite in einem Branch.
- Öffne einen Pull Request, der die Issue-Nummer nennt.
Rechercherichtung
Beginne mit dem verknüpften Playground-Beispiel und vergleiche die Typisierung der Gruppenindizes mit der äußeren Änderung an RegExpIndicesArray in Pull Request #61079. Die Arbeit ist abgeschlossen, wenn TypeScript für den gezeigten Code meldet, dass der Index der benannten Gruppe möglicherweise undefined ist, während gültige Typisierungen für Gruppen erhalten bleiben, die am Match teilgenommen haben.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Bewertung
- Tech-Stack
- javascript, typescript
- Bereich
- compilers
- Issue-Typ
- Bug
- Schwierigkeit
- 3/5
- Geschätzter Aufwand
- 1-2 Tage
- Aktivitätsstatus
- Ruhig
- Klarheit
- Klar beschrieben
- Anfängerfreundlichkeit
- 68/100