【发布时间】:2021-03-24 04:57:44
【问题描述】:
我发现函数参数缺少类型错误报告:
private _toggle(updates: I_Type | null) {
const should_toggle = this.thing && !updates.foo
// ...
}
updates 应该是 I_Type 或 null 类型之一。但是,!updates.foo 在不使用可选链接时不会显示类型错误。 IE。如果!updates?.foo 有?. 运算符,则类型错误不应显示。
我不确定我是否误解了什么,或者我的 eslint/tslint 配置有误。 !updates.foo 不应该导致类型错误吗?
更新
根据 VLAZ 的评论,解决方案是将 strict 添加到 tsconfig compilerOptions。
【问题讨论】:
-
您是否启用了
strictNullChecks编译器选项或strict? -
@VLAZ 就是这样 - 非常感谢。在 tsconfig compilerOptions 中添加了
strict: true。
标签: typescript eslint tslint nrwl-nx