Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

readonly function arguments #29742

Closed
5 tasks done
mohsen1 opened this issue Feb 5, 2019 · 1 comment
Closed
5 tasks done

readonly function arguments #29742

mohsen1 opened this issue Feb 5, 2019 · 1 comment
Labels
Duplicate An existing issue was already created

Comments

@mohsen1
Copy link
Contributor

mohsen1 commented Feb 5, 2019

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 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.
@RyanCavanaugh
Copy link
Member

Duplicate #18497

@RyanCavanaugh RyanCavanaugh added the Duplicate An existing issue was already created label Feb 5, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Duplicate An existing issue was already created
Projects
None yet
Development

No branches or pull requests

2 participants