Property '...' is declared but never used
Asked Answered
M

3

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

Makowski answered 26/7, 2017 at 7:39 Comment(2)
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-secureMakowski
You don't have to console.log() to fake use a variable, just do something like () => this.el;.Teniafuge
R
3

Just set your variable as public

constructor(public el: ElementRef) {  }

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

Rife answered 7/12, 2017 at 13:7 Comment(0)
R
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

Rowney answered 14/4, 2020 at 12:58 Comment(0)
L
0

Set this in your tslist.json

"noUnusedLocals": false,
"noUnusedParameters": false
Larrigan answered 12/8, 2017 at 11:25 Comment(1)
exactly what I wanted to avoidMakowski

© 2022 - 2024 — McMap. All rights reserved.