I am trying to get the scroll position using the following code:
useEffect (()=>{ document.addEventListener("scroll", e => { let scrolled = document.scrollingElement.scrollTop; if (scrolled >= 5){ setPos("moved") } else { setPos("top") } }) },[])
Typescript complains about the document.scrollingElement.scrollTop saying that it is possibly null. How do I avoid this error and keep typescript happy?