I have a private property declared in the constructor and also used in the constructor to retrieve some value. I get TS6138: PROPERTY 'xxxx' is declared but never used.
constructor(private xxxx: Ixxxx) {
this.abc = xxxx.get();
}
I am upgrading to typescript 2.4.2. If I remove private then the error goes away. Obviously the property becomes public which I don't want.
The warning is correct, you're referencing the constructor argument, not the property. If you want to access the property, you'd have to:
constructor(private xxxx: Ixxxx) { // xxxx is constructor arg and private property
this.abc = this.xxxx.get();
}
If you're not planning on using the property anywhere else in your class, you might as well remove the private modifier and use the constructor argument instead:
constructor(xxxx: Ixxxx) { // xxxx is constructor arg
this.abc = xxxx.get();
}
Doing this will not result in xxxx becoming a public property. Only adding the public keyword will do that:
constructor(public xxxx: Ixxxx) { // xxxx is constructor arg and public property
this.abc = this.xxxx.get();
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With