'My js scroll animation is not working, i see a lot of ',' expected ts (1005) and (type annotations can only be used in typescript files)

I'm following a tutorial and I'm near the end, my scrolling animation doesn't seem to work? could anyone point out if I have any mistakes with my javascript as I'm fairly new?

https://www.youtube.com/watch?v=afaqr875gUE&t=486s (in case you were wondering what the tutorial was)

code:

document.lastScrollPosition = 0;
document.lastCentered = 0;
document.onWayTo = null;

document.addEventListener('scroll', listener: () => {
  const direction = window.pageYOffset - document.lastScrollPosition > 0 'down' : 'up';
  const sections = [...document.querySelectorAll('selection')];

  if(document.onWayTo === null) {
    const destIndex = direction === 'up' ? document.lastCentered - 1 : document.lastCentered + 1;
    if(destIndex >= 0 && destIndex < sections.length) {
      console.log({destIndex,direction});
     document.onWayTo = destIndex;
      window.scroll(x: 0, sections[destIndex].offsetTop);
    }
  }
  


  sections.forEach((section,index : number) => {
    if(window.pageYOffset === section.offsetTop) {
      document.lastCentered = index;
      section.className = 'action';
      if (document.onWayTo === index) {
        document.onWayTo = null;
      }

    } else{
      section.className = '';
    }

  })



  document.lastScrollPosition = window.pageYOffset;

})


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source