javascriptregexjsdoc

Is there a type for a regular expression in JSDoc


I have a regular expression stored in a variable like this:

const regex = /^(?=.*[A-Za-z])(?=.*\d)[A-Za-z\d]{1,}$/

I would now like to provide a type using JSDoc. VSCode intellisense suggests:

@type {{}}

which of course it is. But I am wondering if there is a way to be a little bit more precise by calling it something like:

@type {regex}

I have been searching the docs and I have been googling and stackoverflowing a few times over past week, but I cannot find a way to define a regular expression in JSDoc.


Solution

  • The Solution:

    /** @type {RegExp} */
    const regex = /^(?=.*[A-Za-z])(?=.*\d)[A-Za-z\d]{1,}$/;