chad-loder

Valibot regex output type narrowing: compile-time inference of regular expressions to precise types

10
0
100% credibility
Found May 11, 2026 at 10 stars -- GitGems finds repos before they trend. Get early access to the next one.
Sign Up Free
AI Analysis
TypeScript
AI Summary

A tool that supercharges input validation in apps by automatically inferring precise data shapes from patterns and catching errors early.

How It Works

1
🔍 Discover the tool

You hear about a handy helper that makes checking user inputs in your app much smarter and safer.

2
📦 Add it to your project

You easily bring this tool into your app with a quick setup.

3
Describe perfect inputs

You write a simple pattern describing exactly what good inputs should look like, such as status words or number formats.

4
🧠 Get instant smarts

Your app now automatically understands and suggests only the right kinds of inputs as you build.

5
Catch mistakes early

Any slip-ups in your input descriptions are spotted right away, before anything goes wrong.

🎉 Build with confidence

Your app handles user data perfectly, with no guesswork and full reliability.

Sign up to see the full architecture

4 more

Sign Up Free

Star Growth

See how this repo grew from 10 to 10 stars Sign Up Free
Repurpose This Repo

Repurpose is a Pro feature

Generate ready-to-use prompts for X threads, LinkedIn posts, blog posts, YouTube scripts, and more -- with full repo context baked in.

Unlock Repurpose
AI-Generated Review

What is valibot-typed-regex?

This TypeScript library supercharges Valibot schemas with typed regex validation. Pass a string literal regex pattern to `typedRegex()`, and it delivers compile-time inference of precise output types—like narrowing strings to unions ("active" | "inactive") or templates (`${number}.${number}.${number}` for semvers)—while validating regular expressions syntax before runtime. Unlike Valibot's built-in `regex()`, which always outputs `string`, this ensures type narrowing without RegExp objects, sidestepping TypeScript's regex literal erasure.

Why is it gaining traction?

It fixes a core pain: Valibot regex outputs loose `string` types, forcing manual narrowing or casts downstream. Here, simple patterns yield exact literals or unions (e.g., HTTP methods: "GET" | "POST"), complex ones fallback safely to `string` with syntax checks intact. Compile-time validation catches typos like unclosed groups instantly, making TypeScript hovers and autocomplete actually useful for regex-heavy validation.

Who should use this?

Valibot users building APIs or forms with strict string formats—think backend devs typing status enums, config parsers for semvers or ISO dates, or frontend folks validating user inputs like hex colors or UUIDs. Ideal if you're chaining `v.pipe(v.string(), typedRegex(...))` and tired of `string` everywhere.

Verdict

Promising for Valibot shops craving precise regex types, with solid docs, exhaustive tests, and a clean API—installs as a peer dep. At 10 stars and 1.0% credibility, it's early alpha; production teams wait for adoption, but tinkerers grab it now.

(187 words)

Sign up to read the full AI review Sign Up Free

Similar repos coming soon.