Is there a way to evaluate conditions in TypeScript without using short-circuiting? TypeScript does not support &
or |
for boolean types. I need to avoid short-circuit checking because I call the showErrors function inside the isValueValid function.
Consider the following functions:
function isValue1Valid(){
if(value1 === 0) return true;
showErrors1();
return false;
}
function isValue2Valid(){
if(value2 === 0) return true;
showErrors2();
return false;
}
Now, when evaluating the condition:
if(isValue1Valid() & isValue2Valid()){
//Submit data
}
Another approach could be:
if(isValue1Valid() & isValue2Valid()){
//Submit data
return;
}
showErrors1()
showErrors2()
However, I prefer calling it inside the isValueValid function as I think it's more intuitive to show errors by default whenever there's an error.