Ondřej Chrastina
Menu
Extreme TypeScript: Mastering Recursion and Inference via Type-Level Arithmetic

Extreme TypeScript: Mastering Recursion and Inference via Type-Level Arithmetic

Meetup talk in Brno for Next.js & Strapi developers - a deep-dive into TypeScript's type system as a programming language of its own. Built around the story of a Haskell-inspired calculator with zero runtime code, teaching recursion, conditional types, and infer as practical tools for reading real library types.

Back to talks
Released: Thu Apr 23 2026
  • Recording

The origin story

An engineer on my team who was heavily invested in Haskell once brought something unusual to a 1-on-1: a functional calculator built entirely within TypeScript's type system - zero runtime code allowed. While practically "useless" for business logic, it turned out to be the ultimate educational tool for understanding how libraries like Zod, Prisma, and tRPC work under the hood.

What the talk covered

  • Counting with Tuples - TypeScript doesn't do math natively; using length on Tuple types to represent numbers.
  • Recursive Conditional Types - how to loop without for loops, using recursive types for compile-time computation.
  • Pattern Matching with infer - destructuring types to extract values; the key to reading complex library definitions.
  • Practical payoff - de-obfuscating scary type definitions from popular libraries and debugging "Type instantiation is excessively deep" errors.

Who it was for

Developers who use TypeScript day-to-day but find themselves copy-pasting generics from Stack Overflow without understanding them. After this talk, the mental model for recursive types and inference is concrete - not just theoretical.

Resources

  • Slide deck
  • Twitter
  • GitHub
  • LinkedIn
  • Facebook
  • Instagram
  • YouTube
  • Medium
  • dev.to
  • Discord
    • © Ondřej Chrastina 2020
    • Original Design: HTML5 UP
    • 💾 Source code - use GitHub issues for feedback 🙌
  • I am | Home
  • I write | Journal
  • I Code | Projects
  • I speak | Talks
  • PWA series
  • GitHub
Close