allow initialization in the constructor
See original GitHub issueFor class, the following should be allowed, right? But I get a warning.
class Foo {
readonly bar = 1; // OK
readonly baz: string;
constructor() {
this.baz = "hello"; // OK
}
}
tslint warning
[tslint] Modifying properties of existing object not allowed. (no-object-mutation)
tsconfig.json
{
"extends": [
"../../../../tslint.json"
],
"rules": {
"readonly-keyword": [true, "ignore-interface", "ignore-class"],
"readonly-array": true,
"no-let": true,
"no-this": true,
"no-mixed-interface": true,
"no-object-mutation": true
}
}
Issue Analytics
- State:
- Created 6 years ago
- Comments:5 (3 by maintainers)
Top Results From Across the Web
Explicit initialization with constructors (C++ only) - IBM
A class object with a constructor must be explicitly initialized or have a default constructor. Except for aggregate initialization, explicit initialization ...
Read more >Constructors and member initializer lists - cppreference.com
Constructor is a special non-static member function of a class that is used to initialize objects of its class type.
Read more >Constructors for Initialization
A special member function of a class, called a constructor, is often introduced to initialize the values of some or all member variables...
Read more >2.2. Creating and Initializing Objects: Constructors
Constructors initialize the attributes in newly created objects. · A constructor signature is the constructor name followed by the parameter list which is...
Read more >A Guide to Java Initialization - Baeldung
Take a look at the different ways to initialize primitives and objects ... Let's discuss constructors and the new keyword in further detail....
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
The
no-object-mutation
already has a ignore-prefix option. @veeramarni could you try to change your tslint.json to the one below and see if it helps?I second this, iv’e just found you’re library recently and have been really happy with no longer having to spam readonly declarations everywhere to remind my team not to mutate.
however having to constantly spam tslint:disable:no-object-mutation in constructors is giving me cancer, please fix this sometime soon :<
ignore prefix [this.] is not a solution as i only want to enable mutation in constructor not anywhere else