Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RegExpMatchArray should extend [string, ...(string | undefined)[]] #49228

Closed
Josh-Cena opened this issue May 24, 2022 · 3 comments
Closed

RegExpMatchArray should extend [string, ...(string | undefined)[]] #49228

Josh-Cena opened this issue May 24, 2022 · 3 comments

Comments

@Josh-Cena
Copy link
Contributor

lib Update Request

Configuration Check

My compilation target is esnext and my lib is the default.

Missing / Incorrect Definition

RegExpMatchArray extends string[], which can lead to unsound behavior.

I understand this can make string matching a little unwieldy, but it has already been unwieldy since regexps aren't generic (ref #32098, #42296), so I suggest we at least ensure correctness.

Sample Code

Playground

const match = /(a)|(b)/.exec("b");

if (match) {
  match.forEach((m) => console.log(m.toUpperCase()));
}

This fails at runtime, because when we have an alternation of capturing groups, all capturing groups will have their corresponding slot in the match array, but some values could be undefined.

Documentation Link

@Josh-Cena Josh-Cena changed the title RegExpMatchArray should extend (string | undefined)[] RegExpMatchArray should extend [string, ...(string | undefined)[]] May 24, 2022
@Josh-Cena
Copy link
Contributor Author

@MartinJohns May I know your point of objection? I understand you usually downvote issues that don't follow the template, but that's not the point here. So I guess it's about making string matching harder to work with?

@MartinJohns
Copy link
Contributor

Because it would be a forced breaking change for a IMO rather uncommon case.

This is also intentional, see: #17053 (comment) (although the comment is quite old.)

@Josh-Cena
Copy link
Contributor Author

Ah, I see. That issue didn't come up in my search. I guess it's still relevant today—going to close it as duplicate, then.

@Josh-Cena Josh-Cena closed this as not planned Won't fix, can't repro, duplicate, stale May 25, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants