Loading video...

Video Failed to Load

Go Home

🔥 Built a smarter regex constructor this weekend 🔥 The output of `.exec` is inferred from capturing groups and it supports *named* groups too! Would you use it if this was open source? #TypeScript

47,979 views • 3 years ago •via X (Twitter)

11 Comments

Gabriel Vergnaud's profile picture
Gabriel Vergnaud3 years ago

More features I could add: - check if your regex string is valid - automatically coerce number patterns like `[0-9]` to number - Add this to TS-Pattern?

Gabriel Vergnaud's profile picture
Gabriel Vergnaud3 years ago

Here is the code if you want to take a look (it's pretty complex) 👉

Gabriel Vergnaud's profile picture
Gabriel Vergnaud3 years ago

By the way, if you want to learn how I build this kind abstractions with smart type inference, you should read Type-Level TypeScript! It features a tom of free content + paid chapter for deep dive in more advanced concepts

David Tai 💙💛's profile picture
David Tai 💙💛3 years ago

Nice! I’ve been working on something similar for a while too, currently on third rewrite and almost done😂 two modes: infer all exact matched literal string or all possible matches as hint

David Tai 💙💛's profile picture
David Tai 💙💛3 years ago

It’s interesting to find that /t extends `${number}`, same goes to /r, /n…etc Any ideas? @mattpocockuk Thanks

Gabriel Vergnaud's profile picture
Gabriel Vergnaud3 years ago

@mattpocockuk That's definitely odd. Have you checked if there is an open issue about this?

Marcelo Terreiro's profile picture
Marcelo Terreiro3 years ago

that's some next-level type programming 😮👏

Gabriel Vergnaud's profile picture
Gabriel Vergnaud3 years ago

Yes! I teach how to do these kinds of things here (in case you don't already know)

Josh's profile picture
Josh3 years ago

🤯

Darryl Yeo・d/acc's profile picture
Darryl Yeo・d/acc3 years ago

I need this!!

Gabriel Vergnaud's profile picture
Gabriel Vergnaud3 years ago

Should I hit the npm publish button?

Related Videos