Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Typescript error TS2322 - for outerRef and innerRef #581

Open
ofirrifo opened this issue Jan 31, 2023 · 3 comments
Open

Typescript error TS2322 - for outerRef and innerRef #581

ofirrifo opened this issue Jan 31, 2023 · 3 comments

Comments

@ofirrifo
Copy link

Bug Report

Describe the Bug

Im getting this error

TS2322: Type 'MutableRefObject<HTMLElement | null>' is not assignable to type 'LegacyRef<HTMLDivElement> | undefined'.   Type 'MutableRefObject<HTMLElement | null>' is not assignable to type 'RefObject<HTMLDivElement>'.     Types of property 'current' are incompatible.       Type 'HTMLElement | null' is not assignable to type 'HTMLDivElement | null'.         Property 'align' is missing in type 'HTMLElement' but required in type 'HTMLDivElement'.  lib.dom.d.ts(6327, 5): 'align' is declared here. index.d.ts(137, 9): The expected type comes from property 'ref' which is declared here on type 'DetailedHTMLProps<HTMLAttributes<HTMLDivElement>, HTMLDivElement>'

Example of use

 const { outerRef, innerRef, items, scrollToItem } = useVirtual<HTMLElement, HTMLElement>({
    itemCount: 1000,
    itemSize: 25,
  });

  return (
    <div ref={outerRef} >
      <div ref={innerRef}>
            ...       
      </div>
   </div>
  );

A clear and concise description of what the bug is.

How to Reproduce

  • Create a react typescript project
  • set both outerRef, innerRef to ref like in the example

Expected Behavior

Not to see the error

Screenshots

Add screenshots to help explain your problem.
Screen Shot 2023-01-31 at 14 11 37

@nickbyte
Copy link

any solution for this?

@holz-at
Copy link

holz-at commented Apr 17, 2023

@ofirrifo @nickbyte have you tried to specify the type as HTMLDivElement instead of HTMLElement?

@at0mat
Copy link

at0mat commented Jun 16, 2023

// By default, the `innerRef` will refer to the type of the `outerRef`
  const { outerRef, innerRef } = useVirtual<HTMLDivElement>();

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants