All Topics
All Topics
Technology
Technology
Design
Design
Programming
Programming
Science
Science
News
News
Gaming
Gaming
Entertainment
Entertainment
Business
Business
Finance
Finance
Sports
Sports
Health
Health
Food
Food
Travel
Travel
Art
Art
Music
Music
Books
Books
Education
Education
Politics
Politics
Personal
Personal
No algorithm. No AI slop. No ads. Just RSS. Pro-human. Indie writers. Real journalism. Open web. Chronological. Hand toasted.

Exploring Immutable-by-Default TypeScript: A Technical Experiment

By

ingve

6mo ago· 6 min readenInsight

Summary

A developer explores whether it's possible to make TypeScript immutable by default without modifying the language itself, similar to Rust's approach where variables are immutable unless explicitly declared mutable. The author attempts to implement this purely through TypeScript's type system, successfully achieving immutability for arrays and records but encountering challenges with regular objects. The article documents the technical exploration and limitations of this approach.

Key quotes

· 5 pulled
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!
My goal was to do this purely with TypeScript, without changing TypeScript itself. That meant no lint rules or other tools.
I spent an evening trying to make TypeScript values immutable by default.
I got it working with arrays and records, but couldn't make it work for regular objects.
Snippet from the RSS feed
I got it working with arrays and records, but couldn't make it work for regular objects.

You might also wanna read