-
Notifications
You must be signed in to change notification settings - Fork 13k
Closed
Labels
Awaiting More FeedbackThis means we'd like to hear from more people who would be helped by this featureThis means we'd like to hear from more people who would be helped by this featureSuggestionAn idea for TypeScriptAn idea for TypeScript
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.
vitalics, vharadkou, MarsiBarsi, demensky, lautarodragan and 22 moreShinigami92 and tracetechnicalIllusionMH and demensky
Metadata
Metadata
Assignees
Labels
Awaiting More FeedbackThis means we'd like to hear from more people who would be helped by this featureThis means we'd like to hear from more people who would be helped by this featureSuggestionAn idea for TypeScriptAn idea for TypeScript