So, I have this piece of code in .ts file:
import {MicroEventInterface} from '../Interfaces'; export default class MicroEvent implements MicroEventInterface { // code
And ESLint throws this error:
I have this config for TypeScript in ESLint:
typescript: { extends: [ 'plugin:@private/private/react' // private rep with React config ], parser: '@typescript-eslint/parser', plugins: [ '@typescript-eslint', 'import' ], settings: { 'import/resolver': { 'node': { 'extensions': [ '.js', '.jsx', '.ts', '.tsx' ], 'moduleDirectory': [ 'node_modules/', 'src/' ] } }, react: { createClass: 'createClass', pragma: 'React', version: '0.14.9' } } }
So, everything seems like fine, but I can't conquer this error.
Any suggestions?
Thanks!
UPD:
Looks like if I console.log(
--- , MicroEventInterface);
error disappears. I think, ESLint does not treat implements
as actual usage.
To apply the ESLint no-unused-vars rule to a block of JavaScript code, we can wrap the code block that we want to apply the rule to with /* eslint-disable no-unused-vars */ and /* eslint-enable no-unused-vars */ respectively. to wrap the code that we want the rule to apply with the comments.
ESLint is a JavaScript linter that you can use to lint either TypeScript or JavaScript code.
To automatically remove unused imports, we will need to add the eslint-plugin-unused-imports plugin. Now, when you run ESLint, you should see error lines saying error '<imported-var>' is defined but never used unused-imports/no-unused-imports for the files where you have unused imports.
This option allows you to programmatically provide an array of one or more instances of a TypeScript Program object that will provide type information to rules.
Source: I am the maintainer of the typescript-eslint
project.
The latest version of the @typescript-eslint
tooling now has full support for scope analysis.
So the steps to fix this are now:
@typescript-eslint/parser
and @typescript-eslint/eslint-plugin
@typescript-eslint/no-unused-vars
no-unused-vars
rule - see this FAQ article in the project.Restart your IDE and you should now see the correct lint errors.
Use @typescript-eslint/no-unused-vars-experimental
and turn off @typescript-eslint/no-unused-vars
.
The issue is resolved in the latter version (experimental).
Sample config:
// .eslintrc { ... "rules": { "@typescript-eslint/no-unused-vars": "off", "@typescript-eslint/no-unused-vars-experimental": "error" } ... }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With