Skip to content

Commit f32bd1b

Browse files
aicestCopilot
andauthored
fix: Update 'onCaughtError' type inference in 'RenderOptions' to work with React v19 (#1438)
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> Co-authored-by: Fai <aicest@users.noreply.github.com>
1 parent a2d37ff commit f32bd1b

File tree

2 files changed

+16
-5
lines changed

2 files changed

+16
-5
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: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -264,11 +264,22 @@ export function testContainer() {
264264
}
265265

266266
export function testErrorHandlers() {
267-
// React 19 types are not used in tests. Verify manually if this works with `"@types/react": "npm:types-react@rc"`
267+
// This test runs under both React 18 and React 19 types. For React 19, verify that 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+
// This option is intended to type-check successfully with React 19 types
270+
// but to fail (produce a type error) with React 18 types.
271+
//
272+
// > Why use `@ts-ignore` instead of `@ts-expect-error`?
273+
// > Semantically, `@ts-expect-error` would be the right choice here:
274+
// > it would fail under React 18 types and be unused under React 19 types.
275+
// > However, when running with React 19 types, TypeScript reports that
276+
// > `@ts-expect-error` is unused, which causes unwanted noise in CI.
277+
// > To avoid those unused-directive diagnostics while still supporting
278+
// > both React 18 and React 19 typings, we pragmatically use `@ts-ignore`,
279+
// > acknowledging that it suppresses any real type errors at this site.
280+
//
281+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment, @typescript-eslint/prefer-ts-expect-error
282+
// @ts-ignore
272283
onCaughtError: () => {},
273284
})
274285
render(null, {

0 commit comments

Comments
 (0)