-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Open
Labels
Awaiting More FeedbackThis means we'd like to hear from more people who would be helped by this featureThis means we'd like to hear from more people who would be helped by this featureSuggestionAn idea for TypeScriptAn idea for TypeScript
Description
π 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
π» Code
const group = /a(?<mid>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
#61079 fixed the same issue for the outer RegExpIndicesArray itself, but not the indices array on the matched groups
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
Awaiting More FeedbackThis means we'd like to hear from more people who would be helped by this featureThis means we'd like to hear from more people who would be helped by this featureSuggestionAn idea for TypeScriptAn idea for TypeScript