Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to fix `declared but its value is never read` false positive?

Tags:

typescript

I have imported desired module:

import ionRangeSlider from 'ion-rangeslider'

Then I used it:

jQuery('#price_range').ionRangeSlider({
    ...
})

But there's this error on import line:

'ionRangeSlider' is declared but its value is never read.ts(6133)

Why does this error appear? I have just used my imported module.

like image 641
JamesJGoodwin Avatar asked Dec 23 '22 22:12

JamesJGoodwin


1 Answers

If you can't drop the import, then you could disable the warning.

Please note that the error could arise from the typescript compiler or TSLint (if you're using TSLint). Both have almost the same warning.

In this case I think it's from the typescript compiler because of the error number. (6133)

Typescript

If this is a typescript error then add before the import // @ts-ignore, e.g.

// @ts-ignore
import ionRangeSlider from 'ion-rangeslider

Note this will disable all warning for the import line. This needs typescript 2.6+

See https://www.typescriptlang.org/docs/handbook/release-notes/typescript-2-6.html

TSLint

If you're using TSLint, which could give the same error, you could disable it as follows.

Add a tslint comment to disable the warning. For example:

// tslint:disable-next-line:no-unused-variable
import ionRangeSlider from 'ion-rangeslider

If you need this for multiple lines, you could drop the "next line", e.g.

// tslint:disable:no-unused-variable

Recommended then to enable it later in the file:

// tslint:enable:no-unused-variable

See https://palantir.github.io/tslint/usage/rule-flags/

like image 170
Julian Avatar answered May 17 '23 23:05

Julian