Skip to content

RegExpExecArray is missing a type definition for the groups property #30921

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

Closed
OmgImAlexis opened this issue Apr 13, 2019 · 8 comments
Closed
Labels
Question An issue which isn't directly actionable in code

Comments

@OmgImAlexis
Copy link

OmgImAlexis commented Apr 13, 2019

TypeScript Version: I'm using the ts checker with javascript in VS Code so I'm not 100% sure on the version I'm using.

Search Terms:
RegExpExecArray
RegExpExecArray groups
exec groups
regex groups

Code

// GF116 [GeForce GTX 550 Ti] --> GeForce GTX 550 Ti
const regex = new RegExp(/.+\[(?<gpuname>.+)\]/);
regex.exec('GF116 [GeForce GTX 550 Ti]').groups.gpuname;

Expected behavior:
No error.

Actual behavior:
Property 'groups' does not exist on type 'RegExpExecArray'.ts(2339)

Related Issues:
#17094

@MartinJohns
Copy link
Contributor

MartinJohns commented Apr 14, 2019

Duplicate of #29465.

edit: .. or not? The other issue is about RegExprMatchArray. Not sure what the difference is.

@OmgImAlexis
Copy link
Author

OmgImAlexis commented Apr 14, 2019

@MartinJohns looks like RegExpExecArray also needs the fix.

Trying the stackblitz from that issue with this code still shows this.

Property 'groups' does not exist on type 'RegExpExecArray'.
// GF116 [GeForce GTX 550 Ti] --> GeForce GTX 550 Ti
const regex = new RegExp(/.+\[(?<gpuname>.+)\]/);
regex.exec('GF116 [GeForce GTX 550 Ti]').groups.gpuname;

@MartinJohns
Copy link
Contributor

Trying the stackblitz from that issue with this code still shows this.

The issue explicitly says that the Stackblitz website is using outdated versions...

When you set your target to es2018, then your code works. #29465 (comment)

@RyanCavanaugh RyanCavanaugh added the Question An issue which isn't directly actionable in code label Apr 16, 2019
@OmgImAlexis
Copy link
Author

Trying this on the playground again no longer works. I tried es2018, es2019, es2020 and esnext.

Version: v3.9.0-dev.20200407
Config:
Screen Shot 2020-04-09 at 1 17 29 pm

const regex = new RegExp(/^.+: ID (?<id>\S+)(?<name>.*)$/);
const line = 'test string';
const groups = regex.exec(line)?.groups;

Hovering over ?.groups shows "Property 'groups' does not exist on type 'RegExpExecArray'.(2339)".

@counterbeing
Copy link

counterbeing commented May 24, 2020

Same on 3.9.3 for me.

For now, i'm doing something like this:

  type AdjustedRegex = RegExpExecArray & { groups: {} };
  const matches = regex.exec(line) as AdjustedRegex;

@OmgImAlexis
Copy link
Author

This is still an issue. Can it please be reopened?

@cyrilchapon
Copy link

Still an issue, target & lib => 2020

@OmgImAlexis
Copy link
Author

@RyanCavanaugh please reopen this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Question An issue which isn't directly actionable in code
Projects
None yet
Development

No branches or pull requests

6 participants