DEV Community

CarlosAndress
CarlosAndress

Posted on

Parameter 'element' implicitly has an 'any' type.

To solve the error we must only type the best way this particular error happened to me with useRef creating a slider here I leave an example of code.

This is the part of the code that was causing the error and I solved it this way I summarized it so that it was not so long.

const Slider = () => {
  const elementRef = useRef<HTMLInputElement>(null);

  const sliderRight=(element:HTMLElement )=>{
    element.scrollLeft += screenWidth - 110
  }
  const sliderLeft=(element: HTMLElement)=>{
    element.scrollLeft -= screenWidth -110
  }


  return (
    <div>
      <div>
        <HiChevronLeft className="hidden md:block text-white text-[30px] absolute
        mx-8 mt-[150px] cursor-pointer" onClick={() => sliderLeft(elementRef.current as HTMLElement)}/>

        <HiChevronRight className="hidden md:block text-white text-[30px] absolute
        mx-8 mt-[150px] cursor-pointer right-0" onClick={() => sliderRight(elementRef.current as HTMLElement)}/>

      </div>
  )
Enter fullscreen mode Exit fullscreen mode

Top comments (0)