Open JoshuaKGoldberg opened 5 years ago
codefix readonlyarray readonly array immutable
It'd be nice to have a codefix for converting non-readonly arrays to readonly.
When converting/refactoring code to be more immutable/readonly-friendly, it's a bit of a pain to manually add these annotations.
readonly
Given this:
function takesArrays(items: /*| |*/string[], moreItems: /*| |*/string[]) { /* ... */ }
...having a codefix to make one or all parameters readonly would be useful:
function takesArrays(items: readonly string[], moreItems: readonly string[]) { /* ... */ }
My suggestion meets these guidelines:
I agree, especially with the introduction of const assertions (#29510) and their readonly tuples.
const
Search Terms
codefix readonlyarray readonly array immutable
Suggestion
It'd be nice to have a codefix for converting non-readonly arrays to readonly.
Use Cases
When converting/refactoring code to be more immutable/
readonly
-friendly, it's a bit of a pain to manually add these annotations.Examples
Given this:
...having a codefix to make one or all parameters
readonly
would be useful:Checklist
My suggestion meets these guidelines: