TLDR Dev · ARTICLES & TUTORIALS

EXPERIMENT: MAKING TYPESCRIPT IMMUTABLE-BY-DEFAULT

evanhahn.com8 min read

Summary from the TLDR Dev newsletter

This exploration into making TypeScript immutable by default was inspired by languages like Rust. By setting the `noLib` flag and creating a custom `lib.d.ts` file, this dev successfully made arrays and Records immutable unless explicitly declared as `MutableArray` or `MutableRecord`. This was done by defining read-only properties and omitting mutable methods in the default type definitions.