Skip to content

[@types/react] Version 18.2.69 and Above: Void Problem with useRef Callback #69416

Discussion options

You must be logged in to vote

You're probably getting types for Canary. But that's not necessarily relevant here since that will be the behavior going forward.

Unfortunately, TypeScript will allow any returntype of functions that can be assigned to () => void. We should've always flagged the original code.

The reason that only surfaces in Canary types and will surface in React 19 types is that ref callbacks can now return a cleanup function. So we're going from () => void to () => (void | (() => void)). Now TypeScript will reject any return type that's not void or () => void.

To help migration, you can use the no-implicit-ref-callback-return codemod like so: npx types-react-codemod no-implicit-ref-callback-return src/

Replies: 2 comments

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Answer selected by GreattitJY
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Pkg: react Discussions related to react
3 participants