admin 管理员组文章数量: 1086019
When I have code:
const test = (testVar) => {
console.log(testVar);
}
I get error in VS Code from TS and also while building TS, that Parameter 'testVar' implicitly has an 'any' type.
, so it's OK. But can I get similar error in ESLint with TypeScript?
Or ESLint serves different purpose in this case (like if I added testVar: any
ESLint will throw error while TS would build ok)?
I'd assume that I could use ESLint to catch all TS errors as well, to have all errors in one place, and not running first ESLint and later test TS as well, to find any errors.
When I have code:
const test = (testVar) => {
console.log(testVar);
}
I get error in VS Code from TS and also while building TS, that Parameter 'testVar' implicitly has an 'any' type.
, so it's OK. But can I get similar error in ESLint with TypeScript?
Or ESLint serves different purpose in this case (like if I added testVar: any
ESLint will throw error while TS would build ok)?
I'd assume that I could use ESLint to catch all TS errors as well, to have all errors in one place, and not running first ESLint and later test TS as well, to find any errors.
Share Improve this question edited Mar 27 at 14:06 jonrsharpe 122k30 gold badges268 silver badges475 bronze badges asked Mar 27 at 13:53 user3235231user3235231 11 Answer
Reset to default 1ESLint is primarily a linter for code style and patterns, not a type checker. However, with TypeScript support, it can catch some type-related issues.
If the question is "Can Eslint catch type error?" the answer is yes, but with limitations.
If you want ESLint to flag implicit any usage, you can enable the @typescript-eslint/no-implicit-any
rule :
{
"rules": {
"@typescript-eslint/no-implicit-any": "error"
}
}
But in fact should you rely on ESLint for type checking ?
No, and here's why:
- TypeScript's type checker is optimized for this work. Running it through ESLint is slower.
- ESLint won't catch all type errors that TypeScript would.
- We typically uses TypeScript compiler (tsc) or ts-loader (Webpack) for type checking and ESLint for code style and patterns
While you can make ESLint catch some type-related issues, it's not a complete replacement for TypeScript's type checking. The most robust setup uses both tools for their primary purposes.
本文标签: typescriptCan ESLint do similar check as TS does with noImplicitAnyStack Overflow
版权声明:本文标题:typescript - Can ESLint do similar check as TS does with noImplicitAny? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://roclinux.cn/p/1744084029a2530785.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论