Skip to content

Conversation

hi-ogawa
Copy link
Contributor

@hi-ogawa hi-ogawa commented Aug 26, 2025

This PR updates @types/react, @types/react-dom and @types/react-test-renderer to latest v19. Previously they were pinned to v18 via resolutions. I removed them, ran pnpm 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).

Copy link

changeset-bot bot commented Aug 26, 2025

⚠️ No Changeset found

Latest commit: ed849c8

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

* `RouterProvider` from `react-router` and ignore this prop
*/
flushSync?: (fn: () => unknown) => undefined;
flushSync?: <R>(fn: () => R) => R;
Copy link
Contributor Author

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

Comment on lines +1544 to +1545
React.Children.forEach<any>(children, (element, index) => {
if (!React.isValidElement<any>(element)) {
Copy link
Contributor Author

@hi-ogawa hi-ogawa Aug 26, 2025

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.

@brophdawg11
Copy link
Contributor

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.

@hi-ogawa hi-ogawa deleted the refactor-types-react-19 branch August 26, 2025 23:00
@hi-ogawa
Copy link
Contributor Author

Aha, good to know the rational. Thanks 🙏

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants