Skip to content

Property 'groups' does not exist on type 'RegExpExecArray | null' when I have set esnext in lib of tsconfig.json #35604

Closed
@liudonghua123

Description

@liudonghua123

TypeScript Version: 3.7.3

Search Terms:

Code

// A *self-contained* demonstration of the problem follows...
// Test this by running `tsc` on the command-line, rather than through another build tool such as Gulp, Webpack, etc.
const pageInfo = `page: 1/12 total: 234 `
const {
  groups: { totalPage, count },
} = /page1\/(?<totalPage>\d+).* total(?<count>\d+) /.exec(pageInfo);
console.info({ totalPage, count })

tsconfig.json

{
  "compilerOptions": {
    // Target latest version of ECMAScript.
    "target": "esnext",
    // Search under node_modules for non-relative imports.
    "moduleResolution": "node",
    // Process & infer types from .js files.
    "allowJs": true,
    // Don't emit; allow Babel to transform files.
    "noEmit": true,
    // Enable strictest settings like strictNullChecks & noImplicitAny.
    "strict": true,
    // Disallow features that require cross-file information for emit.
    "isolatedModules": true,
    // Import non-ES modules as default imports.
    "esModuleInterop": true,
    // https://www.detroitlabs.com/blog/2018/02/28/adding-custom-type-definitions-to-a-third-party-library/
    "typeRoots": [
      "./@types",
      "./node_modules/@types"
    ],
    "lib": [
      "esnext",
      "es2018.regexp"
    ],
  },
  "include": [
    "src",
    "tools"
  ]
}

Expected behavior:
When run tsc, No error or warning shown

Actual behavior:
error TS2339: Property 'groups' does not exist on type 'RegExpExecArray | null'.

Playground Link:
http://www.typescriptlang.org/play/?target=99&ssl=1&ssc=1&pln=5&pc=35#

Related Issues:
#22082

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions