Closed
Description
Search Terms
ReadonlyArray, default
Suggestion
By default type for array is inferred as Array
. It would be better to default to a more strict ReadonlyArray
and if programmer needs mutability — he would explicitly state so. Could be a tsconfig
option to not introduce a breaking change.
Use Cases
readonly value = [0, 1, 2, 3]; // <-- type number[] here
Examples
readonly value = [0, 1, 2, 3];
readonly mutableValue: Array<number> = [0, 1, 2, 3];
Checklist
My suggestion meets these guidelines:
- [✓] This wouldn't be a breaking change in existing TypeScript/JavaScript code
- [✓] This wouldn't change the runtime behavior of existing JavaScript code
- [✓] This could be implemented without emitting different JS based on the types of the expressions
- [✓] This isn't a runtime feature (e.g. library functionality, non-ECMAScript syntax with JavaScript output, etc.)
- [✓] This feature would agree with the rest of TypeScript's Design Goals.