type Foo = {a: number}
let obj: Foo = {} as Readonly<Foo>
let arr: number[] = [] as ReadonlyArray<number>
I understand that the ReadonlyArray
type removes any mutative Array
methods, and that means the readonly array is not adhering to the expected interface of an array.
But I don't understand why readonly objects are considered safe to pass to a function that expects a mutable object. Technically, the readonly object is missing an implicit setter method, so it's not really adhering to the expected mutable interface.