Experiment: Making TypeScript Immutable-by-Default
evanhahn.com·4d·
Flag this post

I like programming languages where variables are immutable by default. For example, in Rust, let declares an immutable variable and let mut declares a mutable one. I’ve long wanted this in other languages, like TypeScript, which is mutable by default—the opposite of what I want!

I wondered: is it possible to make TypeScript values immutable by default?

My goal was to do this purely with TypeScript, without changing TypeScript itself. That meant no lint rules or other tools. I chose this because I wanted this solution to be as “pure” as possible…and it also sounded more fun.

I spent an evening trying to do this. **I failed but made progress! I made arrays and Records immutable by default, but I couldn’t get it wor…

Similar Posts

Loading similar posts...