关于@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
相关产品推荐
相关产品推荐

