Consider the following code example:
declare const isDisabled: {reason: string} | false;
const disabledReason: string = isDisabled?.reason || '';
The the JavaScript code is perfectly valid and it works in runtime, but with typescript you get this error: "Property 'reason' does not exist on type 'false | { reason: string; }'"
Is there a way to make typescript allow this but interpret "reason" as undefined for the case that the property doesn't exist? (Which is the runtime behavior of JavaScript). I expect the resolved type to be string | undefined, and the compilation to pass.