I've got the following TypeScript snippet:
const anchorRef = React.useRef(null);
...
const handleClose = (event: any): void => {
if (anchorRef != null && anchorRef.current != null && anchorRef.current.contains(event.target)) {
return;
}
setOwnState({ ...ownState, open: false });
}
...
<Popper placement='top' id='id-popper' open={ownState.open} anchorEl={anchorRef.current} transition disablePortal>
...
Visual Studio is telling me that Object is possibly null @
anchorRef.current.contains
Since I'm doing all the necessary null checking prior to hitting that, how is that even possible?
Edit 1: Currently anchorRef.current only ever is null, but at the point where it is giving me an error, it has been checked for null. I don't really care that, right now, it only ever is null. I just want to get rid of the TS error.