8

I have many unused params for my functions and constructors, usualy, an underscore does the trick

1) but here I still get the error message

I tried this (or adding an underscore)

/* tslint:disable-next-line:no-unused-variable */
constructor(private el: ElementRef) {  }

with no luck

2) how do we deal with parameters that are only used in the templates, such errors will be triggered ?

I have to console.log to faint using a variable

thanks

Alexander Abakumov
  • 13,617
  • 16
  • 88
  • 129
ninja
  • 463
  • 1
  • 7
  • 14
  • nobody ? come on, I even have to console.log(password) on my login forms to get rid of this issue...this really renders angular anti-secure – ninja Aug 02 '17 at 06:41
  • You don't have to `console.log()` to fake use a variable, just do something like `() => this.el;`. – Simon Hänisch Aug 24 '17 at 22:40

3 Answers3

3

Just set your variable as public

constructor(public el: ElementRef) {  }

Source : https://github.com/palantir/tslint/issues/3094

1

There are could be two reason for this tslint error(Property '…' is declared but never used )

  1. Either variable is getting used in HTML in that case to fixed it use public

    constructor(public el: ElementRef) { }

  2. If variable is getting used only in constructor, hence without this keyword to fix this use just remove public/private

    constructor(el: ElementRef) { }

When we inject this way we will not be able to use it in class other than constructor.

I got very good explanation from Constructor params used without the "this." are marked as unused. and stop-manually-assigning-typescript-constructor-parameters

Vicky Kumar
  • 1,358
  • 1
  • 14
  • 26
0

Set this in your tslist.json

"noUnusedLocals": false,
"noUnusedParameters": false
saiy2k
  • 1,852
  • 1
  • 23
  • 42