Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

> That should make arr[1] possible but arr[1] = 9 impossible.

I believe you want `=`, `push`, etc. to return a new object rather than just disallow it. Then you can make it efficient by using functional data structures.

https://www.cs.cmu.edu/~rwh/students/okasaki.pdf



At TypeScript-level, I think simply disallowing them makes much more sense. You can already replace .push with .concat, .sort with .toSorted, etc. to get the non-mutating behavior so why complicate things.


You might want that, I might too. But it’s outside the constraints set by the post/author. They want to establish immutable semantics with unmodified TypeScript, which doesn’t have any effect on the semantics of assignment or built in prototypes.


Well said. (I too want that.) I found my first reaction to `MutableArray` was "why not make it a persistent array‽"

Then took a moment to tame my disappointment and realized that the author only wants immutability checking by the typescript compiler (delineated mutation) not to change the design of their programs. A fine choice in itself.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: