-
-
Notifications
You must be signed in to change notification settings - Fork 52
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
Infer the literals used in the type of the groups #235
Comments
This is definitely a worthy enhancement. I think @didavid61202 might be working on this very thing (so let's wait to hear from him), but if not then contribution would be very welcome ❤️ |
Hi @michaelschufi, Yes, I've been working on features similar to this, although might be in very different approach, it's a new type inferencing (fully parse, interpret, exact match, permutation all possible values) for a little peek at what's possible (blue text are type hints from Still have to finish writing more robust test cases and testing for some edge cases. |
Sounds awesome! 😀 The inference looks great so far. Tell me if I can help with some testing or similar. |
Definitely would love to have some helps on testing and improving it! ❤️ Will let you know as soon as I finish wrapping it up. 👍 |
Hi @michaelschufi, Here's the repository for the type-level RegExp parser and matcher. Check out examples in the 'tests/index.test-d.ts' file and others when you have some time. Please let me know if you encounter any issues or have any ideas. Thank you! 😄 |
HI @didavid61202 |
Sorry for my late response @didavid61202 Only one negative thing that I noticed: It seems to push either VS Code or the typescript language server to their limits. But this could be because of my pc, VS Code, TS, TLS, the repo itself with many complex examples, or any combination of those things... I have a few minor things that I would like to discuss. E.g. what the |
Hi @michaelschufi, thanks! Do file issues if you have any questions 👍 |
Hi @didavid61202 |
Hi @michaelschufi, thanks for the info! 👍 |
🆒 Your use case
When I create a regexp group using
anyOf
andgroupedAs
, the type of the matched group should be inferred based on the inputs toanyOf
.Similar to the type of the main regexp that gets inferred.
E.g.
Here, the type of
regex
isso the information that the groups have literals of ABC and XYZ respectively is included in the type. However, the type of
is
string | undefined
instead of"A" | "B" | "C"
.🔍 Alternatives you've considered
No response
ℹ️ Additional info
My goal is to use this library in conjunction with colinhacks/zod. magic-regexp complements zod well when it comes to string validation and parsing while still being typesafe.
I'm open to work on this myself. Please let me know where I should have a look to get started with such a feature.
The text was updated successfully, but these errors were encountered: