【发布时间】:2021-05-25 03:57:28
【问题描述】:
我正在尝试使用 typescript 以及普通的 javascript。所以有些文件是 javascript 文件 (.js),而有些是打字稿文件 (.ts)。这行得通。
但是,我在 VSCode 中的 eslint 给了我 Typescript 错误和警告,即使是在纯 javascript 文件中也是如此。
我可以为 .js 文件关闭这些功能,但只要文件是 .ts / .tsx 就保持打开状态吗?
我的 eslint 和 typescript 配置只是 Vercels official typescript example。
.eslintignore:
**/node_modules/*
**/out/*
**/.next/*
.eslintrc.json:
{
"parser": "@typescript-eslint/parser",
"plugins": ["@typescript-eslint"],
"extends": [
"eslint:recommended",
"plugin:react/recommended",
"plugin:@typescript-eslint/recommended",
// Uncomment the following lines to enable eslint-config-prettier
// Is not enabled right now to avoid issues with the Next.js repo
"prettier",
"prettier/@typescript-eslint"
],
"env": {
"es6": true,
"browser": true,
"jest": true,
"node": true
},
"settings": {
"react": {
"version": "detect"
}
},
"rules": {
"react/react-in-jsx-scope": 0,
"react/display-name": 0,
"react/prop-types": 0,
"@typescript-eslint/explicit-function-return-type": 0,
"@typescript-eslint/explicit-member-accessibility": 0,
"@typescript-eslint/indent": 0,
"@typescript-eslint/member-delimiter-style": 0,
"@typescript-eslint/no-explicit-any": 0,
"@typescript-eslint/no-var-requires": 0,
"@typescript-eslint/no-use-before-define": 0,
"@typescript-eslint/no-unused-vars": [
2,
{
"argsIgnorePattern": "^_"
}
],
"no-console": [
2,
{
"allow": ["warn", "error"]
}
]
}
}
tsconfig.json:
{
"compilerOptions": {
"target": "es5",
"lib": ["dom", "dom.iterable", "esnext"],
"allowJs": true,
"skipLibCheck": true,
"strict": false,
"forceConsistentCasingInFileNames": true,
"noEmit": true,
"esModuleInterop": true,
"module": "esnext",
"moduleResolution": "node",
"resolveJsonModule": true,
"isolatedModules": true,
"jsx": "preserve"
},
"exclude": ["node_modules", ".next", "out", "**/*.js", "**/*.jsx"],
"include": ["next-env.d.ts", "**/*.ts", "**/*.tsx"]
}
【问题讨论】:
-
你看到 eslint 忽略文件了吗?
-
还要看看你的tsconfig
-
但我仍然想检查我的
.js/.jsx文件,而不是通过打字稿。我想为这些文件保留其余的 linting 配置 -
您是否尝试过从您的
tsconfig.json中的include数组中删除"**/*.js"? -
您能否在问题中也发布您的 .eslintignore 文件内容?
标签: javascript typescript visual-studio-code next.js eslint