Tslint: no-unused-variable without use of `this`

Created on 19 May 2017  路  1Comment  路  Source: palantir/tslint

Bug Report

Hi, I believe there's an error with the no-unused-variable when not using with this.

You can see my example in Angular with constructor when I'm not using this;

  • __TSLint version__: 5.2.0
  • __TypeScript version__: 2.3.2
  • __Running TSLint via__: Angular CLI (ng lint)

TypeScript code being linted

@Component({
})
class MyComponent {
    constructor(private myService: MyService) {
        myService.method(); // works on TS but fail on tslint
        // this.myService.method(); // tslint pass
    }
}

with tslint.json configuration:

{
    "rules": {
        "no-unused-variable": true
    }
}

Actual behavior

Property 'myService' is declared but never used.

Expected behavior

Should pass

Not A Bug

Most helpful comment

The behavior is correct. The private modifier creates a property with the same name as the parameter.
You're only using the parameter and not the property. Hence the error message Property myService is declared but never used.

>All comments

The behavior is correct. The private modifier creates a property with the same name as the parameter.
You're only using the parameter and not the property. Hence the error message Property myService is declared but never used.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

ghost picture ghost  路  3Comments

zewa666 picture zewa666  路  3Comments

avanderhoorn picture avanderhoorn  路  3Comments

Ne-Ne picture Ne-Ne  路  3Comments

ypresto picture ypresto  路  3Comments