Standardjs no-unused-vars while it's used

佐手、 提交于 2020-02-03 13:06:33

问题


In my Typescript React project, I defined:

export type NavState = { mounted: boolean }

and then in my component I used theme like:

import { NavState } from '../../models/nav'

class Nav extends React.Component<any, NavState> {
  state: NavState = {
    mounted: false
  }
}

but I got red underline for NavState in my import and it says:

'NavState' is defined but never used. (no-unused-vars)standard(no-unused-vars)

In my package.json I have this:

  "standard": {
    "ignore": [
      "node_modules/**",
      "**/__generated__/"
    ],
    "parser": "@typescript-eslint/parser",
    "plugins": [
      "@typescript-eslint"
    ]
  }

and my vs-code settings.json is like this:

{
  "standard.autoFixOnSave": true,
  "standard.enable": true,
  "standard.run": "onType",
  "standard.validate": [
    { "language": "javascript", "autoFix": true },
    { "language": "javascriptreact", "autoFix": true },
    { "language": "typescript", "autoFix": true },
    { "language": "typescriptreact", "autoFix": true }
  ]
}

Why Standardjs can't understand that I used a type alias? and how can I fix it?


回答1:


This should do the trick:

import { NavState } from '../../models/nav'  //eslint-disable-line

Notice the comment on the import line.

Check the docs for more.



来源:https://stackoverflow.com/questions/55039931/standardjs-no-unused-vars-while-its-used

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!