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.
>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;
}