function f(arg1: any+) {
const val1 = arg1?.val; // implication 1: if val1 is truthy => arg1 is also truthy
const val2 = val1?.prop; // implication 2: if val2 is truthy => val1 is also truthy
const query = val2 ? {
someProp: val1.prop // here we know based on implication 2 that val1 is truthy
} : null;
query;
}
See the example below.
Example