Exploring Immutable-by-Default TypeScript: A Technical Experiment
By
ingve
Hand-rolled, kettle-boiled, baked to perfection. Worth every minute at the bakery.
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 pulledI 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.
You might also wanna read
Unconventional Type Casting Techniques in TypeScript
This article explores unconventional methods for type casting in TypeScript, moving beyond the standard 'as' operator. It presents various c
Why Average LLM Use Is Likely Destroying Value in Software Development
The author argues that, contrary to prevailing hype, the average use of Large Language Models (LLMs) is likely destroying value rather than
How AI Accelerated Prototyping: From Idea to Tangible in Record Time
The author reflects on how AI has transformed their prototyping workflow. Previously, the biggest bottleneck was the time needed to scaffold
GitLab 19.0 launches with Secrets Manager, agentic workflows, and self-hosted AI models
GitLab 19.0 has been released, positioning itself as an intelligent orchestration platform for DevSecOps. The release includes expanded secr
bit.ly·19h agoCentralizing Error Handling in Rust with Custom AppError Enums
This article discusses the importance of centralizing error handling in Rust applications using a custom AppError enum combined with map_err
Zig Devlog: Build System Rework Separates Maker and Configurer Processes
This devlog entry from the Zig programming language project announces a major rework of the build system, separating the maker process from
