Hacker News new | ask | show | jobs
Show HN: Typical is TypeScript with type-safety at runtime (typical.elliots.dev)
8 points by elliotshep 158 days ago
Spent a week in the break building a pre-compiler that brings type safety to runtime. Still pretty early, but generally does what it says.

Looking for feedback, code that breaks it (check out the playground), ideas etc.

2 comments

This looks promising - I've always found the schema duplication annoying with Zod/Yup. Would be great to see benchmarks vs Typia/ArkType at https://moltar.github.io/typescript-runtime-type-benchmarks/
Good idea! The only one of the four benchmarks typical can do is AssertLoose (because, typescript isn't that strict!).

Running against the top 5 (+zod+yup) with node 24:

  @sinclair/typebox-(ahead-of-time) - 176 M/ops/s
  ts-runtime-checks - 176 M/ops/s
  ts-auto-guard - 175 M/ops/s
  typia - 173 M/ops/s
  spectypes - 166 M/ops/s
  typical - 150 M/ops/s
  zod - 1.8 M/ops/s
  yup - 0.2 M/ops/s
Top 5 and typical all generate pretty much the same code (a bunch of typeof checks). The only difference with typical is that it that the error throwing involves some string concatenation the others don't (typical logs the bad value, and can be used multiple places so passes in the property name).

The benchmark itself is fine, but very simple. No arrays, only one level of nesting, no reuse of types, no template literals, no generic, no union types etc etc. Gives you a good idea of the general overhead, but isn't really playing to the strengths I think typical might have (hoisting functions that can be reused etc).

But speed is super important if you're intending to validate everywhere, so I'll keep my fork up to date. Thanks for the idea.

Wait, I don't have to change any code for this to work ...? Holy shit