is it possible for an other variable to function as type guard?
assume some code like this
let foo: string | null = Math.random() > .5 ? null : 'bar'
const otherProp = true
const test = foo !== null && otherProp
function foobar(x: string){}
if i would now call foobar(foo) i assume a warning as foo can be null or string and only string is allowed
but if i call it like
if (test){
foobar(foo)
}
it should not warn me as test is only true if foo is not null and so only string remains as type
is something like this possible?