Matt Rickard

Share this post

TypeScript Type System Hacks

blog.matt-rickard.com

Discover more from Matt Rickard

Thoughts on engineering, startups, and AI.
Continue reading
Sign in

TypeScript Type System Hacks

Sep 2, 2023
4
Share this post

TypeScript Type System Hacks

blog.matt-rickard.com
1
Share

TypeScript’s type system is Turing Complete. The type system is extremely advanced — you can model algebraic data types (unions, intersections, tuples), conditional types, mapped types, and more. It is a structural type system. In TS 4.1, template literal types were introduced, making it easy to do string manipulation within the type system so that you can concatenate, compare, and pattern-match the types. Many of the examples below (like TS-SQL) use template literal types.

Some interesting applications built in entirely in the TypeScript type system:

  • SQL database implemented purely in TypeScript type annotations

  • Tokenizer/parser/interpreter on type-level

  • Compile-time spell checker using TypeScript’s type checker 

  • Binary Arithmetic in TypeScript Type System

  • Chess implemented in the Rust and TypeScript type systems

  • Lambda calculus in TypeScript’s Type System

And some other accidentally Turing Complete systems.

4
Share this post

TypeScript Type System Hacks

blog.matt-rickard.com
1
Share
Previous
Next
1 Comment
Share this discussion

TypeScript Type System Hacks

blog.matt-rickard.com
Andrew Smith
Writes Goatfury Writes
Sep 2

Neat! I just learned about Minecraft being Turing-complete. Pretty wild stuff.

Expand full comment
Reply
Share
Top
New
Community

No posts

Ready for more?

© 2023 Matt Rickard
Privacy ∙ Terms ∙ Collection notice
Start WritingGet the app
Substack is the home for great writing