在 eslint.config.js 上运行 tsc 会引发错误

问题描述 投票:0回答:1

我正在使用以下文件运行

tsc --skipLibCheck

eslint.config.js

// @ts-check
import jslint from "@eslint/js"

export default []

tsconfig.json

{
  "compilerOptions": {
    "strict": true,
    "target": "ES5",
    "useDefineForClassFields": true,
    "lib": ["ES2022", "DOM", "DOM.Iterable"],
    "module": "ES2022",
    "skipLibCheck": true,
    "allowJs": true,
    "moduleResolution": "bundler",
    "allowImportingTsExtensions": true,
    "resolveJsonModule": true,
    "isolatedModules": true,
    "noEmit": true,
    "jsx": "react-jsx",
  },
  "include": ["src"],
  "files": ["eslint.config.js"]
}

我收到以下错误:

eslint.config - error TS7016: Could not find a declaration file for module '@eslint/js'. './node_modules/@eslint/js/src/index.js' implicitly has an 'any' type.

如何忽略导入的类型检查?

javascript tsconfig tsc
1个回答
0
投票

如果你只想忽略对无类型导入的类型检查(通过 TS 判断为隐式任何),你可以这样做:

// @ts-expect-error - @eslint/js is not typed
import jslint from "@eslint/js"

export default []

这个 TS 装饰器将在有错误时删除错误,或者在没有错误时引发警告/错误。这将使您知道何时删除装饰器。

不太安全,您可以使用:

// @ts-ignore - @eslint/js is not typed
import jslint from "@eslint/js"

export default []

这将始终忽略类型检查。

由于 ESLint 9 和平面配置相当新,这些类型可能尚未添加到核心库中。接下来,您可能会遇到更多打字等问题;我个人仍然使用8.56,它对现在很多配置的兼容性更好。

祝你的 TypeScript 项目好运:)

© www.soinside.com 2019 - 2024. All rights reserved.