You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
interfaceexample{num: stringval: string}constexamples=[{num: '1',val: 'A'},{num: '2',val: 'B'},{num: '3',val: 'C'},]leta: example|null=nullexamples.find(t=>{a=treturnt.num==='2'})// a is { num: '2', val: 'B' } // but the next line thinks it is of type null and shows compiler errorsif(a!==null&&a.num==='2'){alert(a.val)}
Expected behaviour:
No TS errors.
Actual behaviour:
Once it reaches the if, TS thinks that a must be null, despite it's assignment inside the .find(). After the a !== null, a is assumed to be never and prop access causes errors.