首页 > 解决方案 > 条件始终为假,因为类型“字符串”在 Javascript 中没有重叠错误

问题描述

有一个变量,我正在读取用户的输入。例如:

let userName;
readUserNameFromUser(userName); // Consider this method will read the userName from user 
if (userName === '') {
  //Do Something;
} 

在这种情况下userName === '',我收到此错误: Condition is always false since types '(IFlagBase<any, boolean> & {type: "boolean", allowNo: boolean, default?: Default<boolean>}) | (IFlagBase<any, string> & {type: "option", helpValue?: string, default?: Default<any | undefined>, multiple: boolean, input: string[], options?: string[]} & {completion?: ICompletion})' and 'string' have no overlap 谁能帮我解决这个问题以及为什么会发生?

提前致谢。

标签: javascriptstringconditional-statements

解决方案


推荐阅读