正在加载视频...

视频加载失败

🔥 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,970 次观看 • 3 年前 •via X (Twitter)

11 条评论

Gabriel Vergnaud 的头像
Gabriel Vergnaud3 年前

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 的头像
Gabriel Vergnaud3 年前

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

Gabriel Vergnaud 的头像
Gabriel Vergnaud3 年前

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 💙💛 的头像
David Tai 💙💛3 年前

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 💙💛 的头像
David Tai 💙💛3 年前

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

Gabriel Vergnaud 的头像
Gabriel Vergnaud3 年前

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

Marcelo Terreiro 的头像
Marcelo Terreiro3 年前

that's some next-level type programming 😮👏

Gabriel Vergnaud 的头像
Gabriel Vergnaud3 年前

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

Josh 的头像
Josh3 年前

🤯

Darryl Yeo・d/acc 的头像
Darryl Yeo・d/acc3 年前

I need this!!

Gabriel Vergnaud 的头像
Gabriel Vergnaud3 年前

Should I hit the npm publish button?

相关视频