uhop / node-re2

node.js bindings for RE2: fast, safe alternative to backtracking regular expression engines.
Other
489 stars 53 forks source link

Incompatible types with TypeScript 4.9 #140

Closed JamieMagee closed 1 year ago

JamieMagee commented 1 year ago

After upgrading to TypeScript 4.9 I get the following errors from the TypeScript compiler:

Error: lib/expose.cjs(14,3): error TS2322: Type 'RE2Constructor' is not assignable to type 'RegExpConstructor'
Error: node_modules/re2/re2.d.ts(13,13): error TS2430: Interface 'RE2' incorrectly extends interface 'RegExp'.
  The types returned by 'exec(...)' are incompatible between these types.
    Type 'RE2ExecArray<string> | null' is not assignable to type 'RegExpExecArray | null'.
      Property '0' is missing in type 'RE2ExecArray<string>' but required in type 'RegExpExecArray'.
Error: node_modules/re2/re2.d.ts(28,13): error TS2430: Interface 'RE2Constructor' incorrectly extends interface 'RegExpConstructor'.
  The types returned by 'prototype.exec(...)' are incompatible between these types.
    Type 'RE2ExecArray<string> | null' is not assignable to type 'RegExpExecArray | null'.

You can find the full build output here.

The TypeScript 4.9 changelog includes Correctness Fixes and Breaking Changes lib.d.ts Updates, which is where I assume why the error has started occurring. I haven't yet narrowed down the fix.

JamieMagee commented 1 year ago

It looks like 0 is now a required property for RegExpMatchArray and RegExpExecArray:

https://github.com/microsoft/TypeScript/blob/93bd577458d55cd720b2677705feab5c91eb12ce/src/lib/es5.d.ts#L920-L948

Changed in these PRs:

Adding the 0 property to RE2MatchArray and RE2ExecArray should resolve the issue, but I haven't verified this.

uhop commented 1 year ago

Moved to #142.