Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How can I find the definition of a built-in type like `RegExpExecArray`?

In the following code, the variable x has the type RegExpExecArray | null (according to VSCode).

  const storeIdRegExp = /s(?<storeId>\d+)/u;
  const x = storeIdRegExp.exec(query);

How can I find the definition of RegExpExecArray? I couldn’t find it documented anywhere.


Note: I did find a couple of references in the TypeScript source code, particularly 1.0lib-noErrors.js and lib.es2018.regexp.d.ts (which I assume applies if the compilation target is ES2018+). But that wasn’t easy to find and I’m not 100% sure the union of these interfaces is the correct answer.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

You should write

let x: RegExpExecArray

and then use the "Go to definition" command (ctrl+click)

Then the editor will show you all the pieces of its definition:

// lib.es2018.regexp.d.ts
interface RegExpExecArray {
    groups?: {
        [key: string]: string
    }
}
// lib.es2015.d.ts
interface RegExpExecArray extends Array<string> {
    /**
     * The index of the search at which the result was found.
     */
    index: number;
    /**
     * A copy of the search string.
     */
    input: string;
}
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading