Closed jonaskello closed 5 years ago
With regard to the readonly-array
rule and automatic fixes for it, should
function foo(arr: string[]) {
}
continue to be fixed to
function foo(arr: ReadonlyArray<string>) {
}
or should it now fix to
function foo(arr: readonly string[]) {
}
?
Same question with
function foo(arr: Array<string>) {
}
I'm feeling the fix for Array<string>
should continue to be ReadonlyArray<string>
and the fix for string[]
should change to readonly string[]
.
For nested arrays, the syntax looks like this:
function foo(arr: readonly (readonly string[])[]) {
arr[0] = [1]; // error!
arr[0][0] = 1; // error!
}
I agree on the Array<T>
-> ReadonlyArray<T>
, and T[]
-> readonly T[]
fixes. If you have opted for one syntax you probably want to fix to that same syntax. Another way would be to have multiple fix options and let the user choose, but I'm not sure if that is possible.
It seems typescript 3.4 adds more support for the
readonly
keyword regarding arrays and tuples :-). See the release notes.So the
readonly-keyword
rule probably needs to be updated to support these scenarios: