Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

fix: Update 'onCaughtError' type inference in 'RenderOptions' to work with React v19 #1401

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ export interface RenderOptions<
* @see {@link https://react.dev/reference/react-dom/client/createRoot#parameters createRoot#options}
*/
onCaughtError?: ReactDOMClient.RootOptions extends {
onCaughtError: infer OnCaughtError
onCaughtError?: infer OnCaughtError
}
? OnCaughtError
: never
Expand Down
13 changes: 10 additions & 3 deletions types/test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -266,9 +266,16 @@ export function testContainer() {
export function testErrorHandlers() {
// React 19 types are not used in tests. Verify manually if this works with `"@types/react": "npm:types-react@rc"`
render(null, {
// Should work with React 19 types
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-expect-error
// Should work with React 19 types but intentionally fails with React 18 types.
//
// > Why use `@ts-ignore` instead of `@ts-expect-error`?
// > Default React 19 types work error-free, causing TS compiler
// > to report `@ts-expect-error` as unused (requiring removal).
// > But for compatibility with React 18 types in tests,
// > we have to use `@ts-ignore` instead.
//
// eslint-disable-next-line @typescript-eslint/ban-ts-comment, @typescript-eslint/prefer-ts-expect-error
// @ts-ignore
onCaughtError: () => {},
})
render(null, {
Expand Down
Loading