Ale*_*lan 4 javascript build typescript
我正在尝试将 TypeScript 编译添加到现有的 Javascript 项目中。
AFAIK 这应该是可能的(甚至很容易),您可以通过代码库逐步传播 TS。不幸的是,这不是我所看到的 - 添加打字稿并尝试启动项目后,项目中的每个文件都出现此错误:
Definition for rule '@typescript-eslint/rule-name' was not found
rule-name我的源代码中的任何地方都没有该字符串的实例。
这是我的tsconfig.json:
{
"compilerOptions": {
"baseUrl": "src",
"noImplicitAny": false,
"sourceMap": true,
"target": "es5",
"lib": [
"dom",
"dom.iterable",
"esnext"
],
"allowJs": true,
"allowSyntheticDefaultImports": true,
"strict": false,
"forceConsistentCasingInFileNames": true,
"module": "esnext",
"moduleResolution": "node",
"resolveJsonModule": true,
"isolatedModules": true,
"noEmit": true,
"esModuleInterop": true,
"jsx": "react",
"skipLibCheck": true
},
"include": [
"src",
"types"
],
"exclude": [
"node_modules",
"build"
]
}
Run Code Online (Sandbox Code Playgroud)
我曾尝试添加"checkJs": false到配置并重新启动,但这并没有改变任何东西。
我一直无法在网上找到有关此“规则名称”问题的任何信息。看起来这确实是某种占位符文本,但我找不到来源。
任何人都可以提出任何可以帮助我建立这个项目的建议吗?
小智 9
您遇到的错误来自 ESLint,这意味着您的.eslintrc任何插件中都不存在规则。如果您遵循使用指南@typescript-eslint/eslint-plugin但没有rule-name用实际规则名称替换占位符,则可能会发生这种情况,如此处所示https://www.npmjs.com/package/@typescript-eslint/eslint-plugin
对我来说,在 .eslintrc 文件中添加 plugin:@typescript-eslint/recommulated 就足够了。
"extends": [
...<otherExtentions>...
"plugin:@typescript-eslint/recommended"
]
Run Code Online (Sandbox Code Playgroud)
Ale*_*lan -2
如果您使用react-app-rewiredand customize-cra,则需要确保使用disableEsLint后者;否则 linting 错误会变成打字稿错误并阻止编译。