Closed
Description
Search Terms
readonly parameters, readonly arguments, read only, function
Suggestion
Allow specifying a readonly
modifier to function and method arguments
function foo(mutableString: string, readonly immutableString: string) {
mutableString = 'bar' // ok
immutableString = 'bar' // not ok
}
With #29435 we can do this for rest arguments too:
function foo(readonly ...immutableStrings: string[]) {}
// the same as
function foo(...immutableStrings: readonly string[]) {}
Use Cases
There is a ESLint rule for not allowing overriding incoming function argument no-param-reassign
Checklist
My suggestion meets these guidelines:
- This wouldn't be a breaking change in existing TypeScript/JavaScript codeThis wouldn't change the runtime behavior of existing JavaScript codeThis could be implemented without emitting different JS based on the types of the expressionsThis 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.
Metadata
Metadata
Assignees
Type
Projects
Milestone
Relationships
Development
No branches or pull requests
Activity
RyanCavanaugh commentedon Feb 5, 2019
Duplicate #18497