How to evaluate condition in non short circuit way in typescript?
Typescript does not allow &
or |
for boolean type.
The reason why I need a non short circuit checking is I call showErrors in function isValueValid
.
Given this function
function isValue1Valid(){
if(value1 === 0) return true;
showErrors1();
return false;
}
function isValue2Valid(){
if(value2 === 0) return true;
showErrors2();
return false;
}
Then in my condition
if(isValue2Valid() & isValue2Valid()){
//Submit data
}
Although I can do it like this one
if(isValue2Valid() & isValue2Valid()){
//Submit data
return;
}
showErrors1()
showErrors2()
But I feel to call it inside isValueValid function. In reality I always think to call show errors by default whenever there's an error.
if (process(otherStuff) && valid(stuff))
only to realise that it doesn't work if I swapped the conditions. – Charettevalid1() & valid2()
. – GujaratshowErrors
when invalid inside myvalid1
andvalid2
function. That's why I'm looking for Typescript version of non short circuit. – Gujaratvar valid1 = isValue1Valid(); valid2 = isValue2Valid(); if (valid1 && valid2)
although decoupling the validation logic from the error display might probably be better, so it would look likeif (isValid()) { /* do stuff */ } else { /* display errors */ }
– CharetteXY Problem
? – Gujaratvar msgs = validation1(); msgs.concat(validation2()); if (msgs.length === 0) { return;}
. – Ecumenicist