reactjs - 为什么 eslint 忽略了我的 strictNullChecks 设置?
问题描述
我正在尝试将现有的大型 JavaScript 代码库移植到 TypeScript。我已经安装typescript
并配置了项目以便@typescript-eslint/eslint-plugin
使用@typescript-eslint/parser
它。devDependencies
tsconfig.json
我的(最小)tsconfig.json
是:
{
"compilerOptions": {
"target": "es5",
"module": "esnext",
"alwaysStrict": true,
"strict": true,
"strictNullChecks": true
},
}
在现有的 .tsx 文件上运行 eslint(正确)会显示一些错误:
$ ./node_modules/.bin/eslint ./src/components/JustSomeComponent.tsx
/src/components/JustSomeComponent.tsx
57:75 error Unexpected empty arrow function 'myFunction' @typescript-eslint/no-empty-function
...
✖ 20 problems (8 errors, 12 warnings)
4 errors and 0 warnings potentially fixable with the `--fix` option.
但是,我想确保strictNullChecks
确实启用了该设置,所以我创建了一个新文件并故意犯了一个错误:
import React from 'react';
export default class MyComponent extends React.Component {
render(): React.ReactNode {
const x: number = null; // I would expect an error here!
console.log(x);
return null;
}
}
但是对此文件运行检查不会返回错误:
$ ./node_modules/.bin/eslint ./src/components/MyComponent.tsx
$
删除render()
方法的返回类型会导致错误,因此会执行检查 - 我只是没有收到有关无效分配的警告null
。
知道如何启用strictNullChecks
,或者至少如何调试它被禁用的原因吗?
解决方案
strictNullChecks
是TypeScript功能,而不是ESLint功能。
推荐阅读
- gradle - 在 Intellij/Gradle 中创建包含源代码和测试的平面目录结构?
- python - 将年份和月份名称转换为 pandas 数据框的日期时间列
- python - 如何使用 odoo-xml-rpc 一次在 ODOO 中创建多个值?
- java - 图像在移动时有奇怪的行为?
- java - 从另一个包访问类
- python - 为什么 print("aA".count("")) 打印值 3?
- git - 如何找到 Git repo 的版本
- swift - 从 uiimagepicker 选择时出现剪切问题
- javascript - 如果按钮只有使用 Javascript 的值和名称属性,我如何单击它
- android - OneSignal - 帮我在现有的 webView 中打开 URL ...我很困惑