Force methods to respect readonly signature in interface

35 views Asked by At

This resembles this post, but not a duplicate IMHO

class Person {
  constructor(public age: number, public name: string){} 
}

interface AbstractVisitor {
  visit(_: Readonly<Person>): void;
}

class ConcreteVisitor implements AbstractVisitor {
  visit(p: Person) { p.name = "moish"; }
}

How come ConcreteVisitor does not respect1 the Readonly property in the interface ?


1 no errors with npx tsc --target es2020 --strict main.ts

0

There are 0 answers