-
-
Notifications
You must be signed in to change notification settings - Fork 10.7k
refactor: update react types to v19 #14241
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
Conversation
|
* `RouterProvider` from `react-router` and ignore this prop | ||
*/ | ||
flushSync?: (fn: () => unknown) => undefined; | ||
flushSync?: <R>(fn: () => R) => R; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure what changed but otherwise the typecheck here fails
<RouterProvider router={router} flushSync={ReactDOM.flushSync} /> |
I updated a type to align with ReactDOM.flushSync
https://github.com/DefinitelyTyped/DefinitelyTyped/blob/f2116ac0a107a3a2ac757c78347aa3a59c27e848/types/react-dom/index.d.ts#L17
React.Children.forEach<any>(children, (element, index) => { | ||
if (!React.isValidElement<any>(element)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is related to the breaking change of the default generic from ReactElement<any>
to ReactElement<unknown>
. For now, I opted for adding some any
. Otherwise it becomes element.props: unknown
and typecheck fails with a following code like element.props.children
. This change gives element: ReactElement<any>
and thus element.props: any
to align with previous typing.
This is intentional because RRv7 still supports React 18, so using the types from 18 forces us to be acutely aware when we are opting into a v19-only API. We need to make sure we don't opt-into any 19 APIs in code paths that support v18 (non-RSC). We would plan to drop 18 support in RR v8. |
Aha, good to know the rational. Thanks 🙏 |
This PR updates
@types/react
,@types/react-dom
and@types/react-test-renderer
to latest v19. Previously they were pinned to v18 viaresolutions
. I removed them, ranpnpm update --latest -r @types/react @types/react-dom
, then fixed types manually (mostly removing@ts-expect-error
).For reference, this discussion lists type-related breaking change for v19 DefinitelyTyped/DefinitelyTyped#64451. The only runtime code change is
useRef() -> useRef(undefined)
, which is expected according to DefinitelyTyped/DefinitelyTyped#64920.My motivation is to pick up some recent type improvements such as DefinitelyTyped/DefinitelyTyped#72926 and DefinitelyTyped/DefinitelyTyped#73545 (though I didn't include fixing
RSCRenderPayload.formState
type in this PR. I'll probably try a separate PR for this).