3

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?

Gama11
  • 31,714
  • 9
  • 78
  • 100
Kavoos
  • 377
  • 4
  • 19

1 Answers1

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.

Johnny
  • 1,063
  • 1
  • 11
  • 23