You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

关于@typescript-eslint/strict-boolean-expressions联合类型误报的问询

@typescript-eslint/strict-boolean-expressions 联合类型误报疑问

代码示例

declare const str: string
if (str) { } // 无报错(符合预期)

declare const num: number
if(num) {} // 无报错(符合预期)

declare const u: string | number
if(u) {} // 触发报错:Unexpected value in conditional. A boolean expression is required.(@typescript-eslint/strict-boolean-expressions)

问题说明

使用@typescript-eslint/strict-boolean-expressions规则时,单独的string或number类型变量在条件判断中不会触发规则报错,但联合类型string | number的变量u却被规则提示错误。我认为这种联合类型的条件判断不应被规则报告。

内容的提问来源于stack exchange,提问作者lvjiaxuan

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.21 17:35:55