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

Should interfaces and their properties be implicitly readonly? #41

Closed
ghost opened this issue Sep 8, 2017 · 5 comments
Closed

Should interfaces and their properties be implicitly readonly? #41

ghost opened this issue Sep 8, 2017 · 5 comments

Comments

@ghost
Copy link

ghost commented Sep 8, 2017

With the readonly-keyword rule, Interfaces throw errors if their properties don't have the keyword. Should interfaces and their properties be implicitly readonly?

// Error
export interface IUserAuthenticationResponse {
  result: boolean;
  data: any;
  errors: any[];
}
// Happy
export interface IUserAuthenticationResponse {
  readonly result: boolean;
  readonly data: any;
  readonly errors: any[];
}
// Error
readonly export interface IUserAuthenticationResponse {
  result: boolean;
  data: any;
  errors: any[];
}
@jonaskello
Copy link
Owner

I don't think you can put the readonly modifier directly on an interface like that?

If I compile your last example I get this:

error TS1024: 'readonly' modifier can only appear on a property declaration or index signature.

@ghost
Copy link
Author

ghost commented Sep 11, 2017

Right, but that's what I'm asking. Should that be the case? When are people mutating interfaces? They aren't instantiated by other instances. They're just adhered to within typed entities.

@jonaskello
Copy link
Owner

jonaskello commented Sep 11, 2017

Sure, if you ask me interfaces (and everything else) should be immutable by default in typescript :-).

However if I understand what you are asking correctly this is nothing we can change within the scope of tslint-immutable. Perhaps this discussion should be moved to the typescript repo? Or do you have some action in mind that fits within the scope of this repo?

@jonaskello
Copy link
Owner

I'm closing this as I cannot see any action we can take but feel free to continue with the discussion.

@ghost
Copy link
Author

ghost commented Nov 29, 2017

If anyone stumbles upon this, an ignore-interface option has been added to the readonly-keyword rule. https://github.com/jonaskello/tslint-immutable#using-the-ignore-interface-option

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant