Skip to content

Commit f68378e

Browse files
committed
fix: Update 'onCaughtError' type inference in 'RenderOptions' to work with React v19
1 parent 9fc6a75 commit f68378e

File tree

2 files changed

+11
-4
lines changed

2 files changed

+11
-4
lines changed

types/index.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ export interface RenderOptions<
127127
* @see {@link https://react.dev/reference/react-dom/client/createRoot#parameters createRoot#options}
128128
*/
129129
onCaughtError?: ReactDOMClient.RootOptions extends {
130-
onCaughtError: infer OnCaughtError
130+
onCaughtError?: infer OnCaughtError
131131
}
132132
? OnCaughtError
133133
: never

types/test.tsx

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -266,9 +266,16 @@ export function testContainer() {
266266
export function testErrorHandlers() {
267267
// React 19 types are not used in tests. Verify manually if this works with `"@types/react": "npm:types-react@rc"`
268268
render(null, {
269-
// Should work with React 19 types
270-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
271-
// @ts-expect-error
269+
// Should work with React 19 types but intentionally fails with React 18 types.
270+
//
271+
// > Why use `@ts-ignore` instead of `@ts-expect-error`?
272+
// > Default React 19 types work error-free, causing TS compiler
273+
// > to report `@ts-expect-error` as unused (requiring removal).
274+
// > But for compatibility with React 18 types in tests,
275+
// > we have to use `@ts-ignore` instead.
276+
//
277+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment, @typescript-eslint/prefer-ts-expect-error
278+
// @ts-ignore
272279
onCaughtError: () => {},
273280
})
274281
render(null, {

0 commit comments

Comments
 (0)