Home > Back-end >  Why does IntelliJ propose RegExp.[Symbol.matchAll] instead of RegExp.matchAll?
Why does IntelliJ propose RegExp.[Symbol.matchAll] instead of RegExp.matchAll?

Time:09-18

The code-completion in IntelliJ only proposes RegExp.[Symbol.matchAll], but not RegExp.matchAll:
enter image description here

Typescript config settings:

  "compilerOptions": {
    "lib": ["es2020"],
    "target": "es2020",
  },

What can be the reason for this?

More info:

  • /x/[Symbol.matchAll]("axb") works at runtime (NodeJs 14).
  • string.matchAll() works, but RegExp.matchAll() doesn't:
    enter image description here
  • Typescript version 4.3.5

CodePudding user response:

Because there is no Regex.prototype.matchAll method.

There is a String.prototype.matchAll method (which calls the method keyed to Symbol.matchAll under the hood), and there is a method on Regex.prototype[Symbol.matchAll] that behaves similarly, which is why your IDE is autocompleting it that way for you. Not sure why they decided to have the convenience method for Strings but not Regexes.

  • Related