-
-
Notifications
You must be signed in to change notification settings - Fork 138
Description
Hi ArkRegex team 👋
First off, ArkRegex is a really impressive project. The idea of statically typed regexes is fantastic.
I’m opening this issue to clarify an assumption I have made, and to confirm whether the behavior I’m seeing is intended.
Background / expectation
From the docs and blog posts, I was under the impression that regex() is a drop-in replacement for new RegExp(), meaning:
- literal patterns get strong type inference
- dynamic patterns still work, but with degraded (widened) typing
In other words, I expected something like this to type-check (even if with less precise types):
const r = regex(dynamicPattern) // dynamicPattern: stringWhat I’m observing instead
In practice, when the pattern is dynamic (string), the call often becomes ill-typed, with the parameter inferred as never, for example:
(alias) regex<string, "">(src: never, flags?: "" | undefined): neverThis effectively makes regex() unusable without regex.as for dynamic patterns, even though the equivalent new RegExp(dynamicPattern) is valid.
Concrete example from a real migration attempt:
https://github.com/alexbit-codemod/netlify-cli/pull/5/files#r2660169105
Clarifying question
Is the following statement correct?
ArkRegex’s
regex()function only accepts statically analyzable (literal) string patterns at the type level; dynamic patterns requireregex.as.
If this is correct, then:
regex()is not a drop-in replacement fornew RegExp()at the type level- dynamic patterns must always be rewritten to
regex.as<...>(...)in order to compile
If this is not correct:
- is there a recommended way to use
regex()with dynamicstringpatterns without immediately resorting toregex.as?
Why this matters
I’m building a codemod to migrate new RegExp(...) to ArkRegex, and this distinction affects whether:
- dynamic cases can be rewritten mechanically, or
- must be skipped or rewritten with
regex.asplus TODOs
Thanks in advance for the clarification. 🙏
Metadata
Metadata
Assignees
Labels
Type
Projects
Status