Skip to content

RegExpExecArray should have explicit always-defined properties #50520

Closed
@DanielRosenwasser

Description

@DanielRosenwasser

[L]ooking a little closely at the ECMAScript spec, I do think that there is a mismatch between what we have and what gets created in the runtime. RegExpBuiltinExec says that the following are created unconditionally:

  • an index property
  • an input property
  • a property at index 0
  • a groups property that is always set, but may be undefined

So RegExpExecArray should look something kind of like

// src/lib/es5.d.ts

interface RegExpExecArray extends Array<string> {
    // always present
    index: number;

    // always present
    input: string;

    // always present - helpful for '--noUncheckedIndexedAccess'
    0: string;
}
// src/lib/es2018.regexp.d.ts

interface RegExpExecArray extends Array<string> {
    // always present - helpful for '--exactOptionalPropertyTypes'
    groups: { [key: string]: string } | undefined;
}

Derived from content posted by @DanielRosenwasser in #50211 (comment)


In additionl to the above, it seems like RegExpMatchArray/RegExpExecArray are sometimes both returned from functions that undergo the same internal code paths. So we should probably ensure that one is compatible with the other, and have a test that ensures as much.

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugA bug in TypeScriptDomain: lib.d.tsThe issue relates to the different libraries shipped with TypeScriptEffort: CasualGood issue if you're already used to contributing to the codebase. Harder than "good first issue".Help WantedYou can do this

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions