-
Notifications
You must be signed in to change notification settings - Fork 3
Description
Based on https://www.typescriptlang.org/docs/handbook/release-notes/typescript-3-4.html#a-new-syntax-for-readonlyarray, it looks like readonly Foo[] is syntactic sugar for ReadonlyArray. It looks like this is effectively an array that just can't have new values assigned/appended, but the elements themselves are still mutable - so typescript wants to be sure that a readonly array is never passed to code that is expecting to be able to mutate that array.
A mutable array can always be assigned to an immutable array, but the converse is not true. It seems like by this principle, any method argument of type array should probably be declared as readonly unless the method is expected to write to it?
My best guess here is that we could introduce a @TsReadonly annotation to add the keyword readonly to parameters. Creating it as a target=TYPE_USE would let this be allowed on return type and generic args as well.