Comment

Comment by DexesTTP

TS allows you to pass a read-only object to a method taking a read-write value:

    type A = { value: number; }
    function test(a: A) { a.value = 3; }
    function main() {
      const a: Readonly<A> = { value: 1 };
      // a.value = 2; <= this errors out
      test(a); // this doesn't error out
      console.log(a); // shows 3
    }
parent DexesTTP 2 years ago

Discussion

Live from the official Hacker News API

A modern reader for Hacker News · SvelteKit + Skeleton