问题
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