Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Get "No unused variables" Error when import type definitions in TypeScript #1291

Closed
kiochan opened this issue Jun 4, 2019 · 2 comments

Comments

@kiochan
Copy link

commented Jun 4, 2019

What version of standard?
12.0.1

What operating system, Node.js, and npm version?
OS: Mac OS X 10.14.5 18F132
Node.js version: v12.0.0
Yarn version: 1.16.0

What did you expect to happen?
I want format my typescript code use standard **/*.ts --fix and I run standard with @typescript-eslint/parser and @typescript-eslint/eslint-plugin .
It should be error free.

package.json

{
  "standard": {
      "parser": "@typescript-eslint/parser",
      "plugins": [
        "@typescript-eslint/eslint-plugin"
      ]
    }
}

types.ts

export type TypedObject<T> = {
    [key: string]: T
}

test.ts

import { TypedObject } from './types'
export const myObject: TypedObject<Date> = {}

What actually happened?
It caused an error below:

standard: Use JavaScript Standard Style (https://standardjs.com)
  ******/test.ts:1:10: 'TypedObject' is defined but never used.
@despian

This comment has been minimized.

Copy link

commented Jun 20, 2019

You can fix this per file by adding:

/* eslint no-unused-vars: "off" */
/* eslint @typescript-eslint/no-unused-vars: "error" */

Obviously, this isn't a great solution for projects with many .ts files.

I think #1283 address this and some other issues better.

@feross

This comment has been minimized.

Copy link
Member

commented Aug 11, 2019

I'd like to have solve this in a future version of standard. In the meantime, you can use standardx:

  1. npm install standardx
  2. Rename the "standard" field in your package.json to "standardx"
  3. Add a new "rules": [] section with the following rules:
"rules": {
  "no-unused-vars": "off",
  "@typescript-eslint/no-unused-vars": "error"
}

Let's close this issue in favor of: #1283 (comment)

@feross feross closed this Aug 11, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
3 participants
You can’t perform that action at this time.