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

Rule proposal: Enforce read-only #514

sindresorhus opened this issue May 12, 2019 · 1 comment

Rule proposal: Enforce read-only #514

sindresorhus opened this issue May 12, 2019 · 1 comment


Copy link

@sindresorhus sindresorhus commented May 12, 2019

I would like to enforce function arguments to be read-only (immutable), to prevent me from accidentally mutate user input. I've encountered many modules that accidentally modify a user-supplied options-object.

I would also like to enforce function return values to not be read-only, as that's annoying for users without much benefit, since it's not actually enforced at runtime. This one might be slightly controversial, so could be an option.


function foo(input: number[]): void {}

function foo(input: string): Readonly<Point> {}


function foo(input: readonly number[]): void {}

function foo(input: string): Point {}

The rule should support enforcing read-only for:


This comment has been minimized.

Copy link

@kitsonk kitsonk commented Jun 4, 2019

I would like to see the ability to allow the return of read-only values in function arguments (so optional). While it can be annoying, if the internals of a function have retained references to objects/arrays that you expect to be immutable, then you would want to be able to express that intent of "look, but don't touch, or it might get ugly".

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
None yet
3 participants
You can’t perform that action at this time.