Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

294
Views
Why doesn't VS Code/TypeScript recognize the indices property on the result of Regex.exec?

If you look this exec documentation, it says a property should exist called indices:

An array where each entry represents a substring match. Each substring match itself is an array where the first entry represents its start index and the second entry its end index. The indices array additionally has a groups property which holds an object of all named capturing groups. The keys are the names of the capturing groups and each value is an array with the first item being the start entry and the second entry being the end index of the capturing group. If the regular expression doesn't contain any capturing groups, groups is undefined.

Here is my code:

  const ex = / ([a-z])/dg.exec(
    "a b c d e f"
  );
  if (ex) {
    const x = ex.indices; // Error! Property 'indices' does not exist on type 'RegExpExecArray'.
  }

I kind of feel like I'm missing something really obvious. Why doesn't this compile and how do I get it to?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

The proposal that added .indicies is pretty new - it only advanced to Stage 4 in the TC39 process less than a year ago, and TypeScript hasn't integrated it yet. There is an open issue on the TS github to add .indicies, but it hasn't been fixed yet.

In short, if you want this to just work, you'll have to wait until someone contributes this new feature to TypeScript typings.

You could, of course, define a type yourself, and use as to assert:

type RegExpMatchArrayWithIndices = RegExpMatchArray & { indices: Array<[number, number]> };

const ex = / ([a-z])/dg.exec(
    "a b c d e f"
);
if (ex) {
    const x = (ex as RegExpMatchArrayWithIndices).indices;
}
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!