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

nodeRef type not compatible with React 19 typings #768

Open
Philipp91 opened this issue Dec 7, 2024 · 0 comments · May be fixed by #769
Open

nodeRef type not compatible with React 19 typings #768

Philipp91 opened this issue Dec 7, 2024 · 0 comments · May be fixed by #769

Comments

@Philipp91
Copy link

Philipp91 commented Dec 7, 2024

To reproduce, run the type checker with the new React version, e.g. like this:

  1. Fork this repo
  2. Change to react v19 in package.json, especially the typings:
    "@types/react": "^19.0.1",
    "@types/react-dom": "^19.0.1",
    "react": "^19.0.0",
    "react-dom": "^19.0.0",
    "react-frame-component": "^5.2.6",
    "react-test-renderer": "^19.0.0",
    
  3. npm update, cd typings
  4. ../node_modules/typescript/bin/tsc

While it worked fine with the older React version, now it throws this error:

test.tsx:33:5 - error TS2322: Type 'RefObject<HTMLDivElement | null>' is not assignable to type 'RefObject<HTMLElement>'.
  Type 'HTMLDivElement | null' is not assignable to type 'HTMLElement'.
    Type 'null' is not assignable to type 'HTMLElement'.

33     nodeRef={nodeRef}
       ~~~~~~~

  index.d.ts:53:5
    53     nodeRef?: React.RefObject<HTMLElement>,
           ~~~~~~~
    The expected type comes from property 'nodeRef' which is declared here on type 'IntrinsicAttributes & IntrinsicClassAttributes<Draggable> & Pick<Readonly<Partial<DraggableProps>>, never> & InexactPartial<...> & InexactPartial<...>'
Philipp91 added a commit to Philipp91/react-draggable that referenced this issue Dec 7, 2024
Fixes react-grid-layout#768.

See also https://react.dev/blog/2024/04/25/react-19-upgrade-guide#useref-requires-argument.

Only a type change is required, because React's typings (DefinitelyTyped) were changed. The implementation in DraggableCore.js itself already tolerates / guard against `.current==null` everywhere.
@Philipp91 Philipp91 linked a pull request Dec 7, 2024 that will close this issue
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

Successfully merging a pull request may close this issue.

1 participant