top | item 46574759

Show HN: Typical is TypeScript with type-safety at runtime

8 points| elliotshep | 1 month ago |typical.elliots.dev

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.

3 comments

order

sbondaryev|1 month ago

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/

elliotshep|1 month ago

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.

Rat_Toupee|1 month ago

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