Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Property '...' is declared but never used

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

like image 498
ninja Avatar asked Jul 26 '17 07:07

ninja


People also ask

Is Declared but its value is never used?

To solve 'is declared but its value is never read' error in TypeScript, prefix any unused parameter name with an underscore, or disable the noUnusedLocals and noUnusedParameters options in your tsconfig. json file to silence the error in your entire project. Here is an example of how the error occurs.

How do I disable TypeScript error?

Use the // @ts-nocheck comment to disable all type checking in a TypeScript file. If you need to disable all type checking for JavaScript files, set the checkJs option to false in your tsconfig. json file. When the option is disabled, errors are not reported in JS files.


2 Answers

Just set your variable as public

constructor(public el: ElementRef) {  }

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

like image 81
etienne grandier-vazeille Avatar answered Sep 28 '22 23:09

etienne grandier-vazeille


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

like image 41
Vicky Kumar Avatar answered Sep 28 '22 22:09

Vicky Kumar