Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

groups does not exist in type KnownPattern<RegExpExecArray> #299

Open
tao-cumplido opened this issue Nov 16, 2024 · 1 comment
Open

groups does not exist in type KnownPattern<RegExpExecArray> #299

tao-cumplido opened this issue Nov 16, 2024 · 1 comment

Comments

@tao-cumplido
Copy link

Describe the bug
I thought this library would be a nice fit for matching named capture groups. Unfortunately it complains that the property groups does not exist in type KnownPattern<RegExpExecArray>. RegExpExecArray extends from Array, maybe that's why it's not recognized correctly. When executed without TS the playground code runs fine and does actually match.

TypeScript playground with a minimal reproduction case

Example: Playground

Versions

  • TypeScript version: 5.6.3
  • ts-pattern version: 5.5.0
@tao-cumplido
Copy link
Author

Just came up with a workaround, more readable with multiple paths too:

import { match, P } from "ts-pattern";

const re = /(?<a>.)/;

match(re.exec("a")?.groups)
  .with(P.nullish, () => 0)
  .with({ a: "a" }, () => 1);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant