Tslint: readonly variables

Created on 13 Oct 2016  路  7Comments  路  Source: palantir/tslint

What do you think about a rule, which checks whether a variable can be made read-only?
Read-Only is a TypeScript 2 Feature. The rule could maybe determined by checking whether a field is assigned only inside the constructor or the field will be initialized at the same place like the declaration.

P2 Accepting PRs Rule Suggestion

Most helpful comment

yeah, this could be pretty cool; it's similar in spirit to the prefer-const rule (https://github.com/palantir/tslint/issues/491)

All 7 comments

yeah, this could be pretty cool; it's similar in spirit to the prefer-const rule (https://github.com/palantir/tslint/issues/491)

Perhaps an extension of this would be a functional-programming-only rule that ensures all function inputs are marked with the Readonly<T> annotation

Scratch that, definitely does not check function inputs. Will put an issue on that project though as it seems more tuned to this type of rule.

It should be configurable for access modifiers. public and protected properties could be assigned outside of the current class context.

Fixed by #2896

Was this page helpful?
0 / 5 - 0 ratings