From b6f320105bd21a52cc946da65765cdc415804cc6 Mon Sep 17 00:00:00 2001 From: Fai Date: Wed, 28 May 2025 23:54:48 +0800 Subject: [PATCH 1/3] fix: Update 'onCaughtError' type inference in 'RenderOptions' to work with React v19 --- types/index.d.ts | 2 +- types/test.tsx | 14 +++++++++++--- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/types/index.d.ts b/types/index.d.ts index bdd60567..439dddbf 100644 --- a/types/index.d.ts +++ b/types/index.d.ts @@ -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 diff --git a/types/test.tsx b/types/test.tsx index 825d5699..9790dea7 100644 --- a/types/test.tsx +++ b/types/test.tsx @@ -266,9 +266,17 @@ 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`? + // > By default, React 19 types run without errors, + // > causing the TS compiler to report `@ts-expect-error` as unused, + // > so this TS directive must be removed. + // > However, to maintain compatibility with React 18 types during CI testing, + // > we had to instead use `@ts-ignore`. + // + // eslint-disable-next-line @typescript-eslint/ban-ts-comment, @typescript-eslint/prefer-ts-expect-error + // @ts-ignore onCaughtError: () => {}, }) render(null, { From 5c7fef727e2f74dbd0088b69dbc26a2b5b529856 Mon Sep 17 00:00:00 2001 From: Fai <4016742+aicest@users.noreply.github.com> Date: Sun, 21 Dec 2025 00:34:52 +0800 Subject: [PATCH 2/3] Update types/test.tsx Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- types/test.tsx | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/types/test.tsx b/types/test.tsx index 9790dea7..4316f92c 100644 --- a/types/test.tsx +++ b/types/test.tsx @@ -266,14 +266,17 @@ 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 but intentionally fails with React 18 types. + // This option is intended to type-check successfully with React 19 types + // but to fail (produce a type error) with React 18 types. // // > Why use `@ts-ignore` instead of `@ts-expect-error`? - // > By default, React 19 types run without errors, - // > causing the TS compiler to report `@ts-expect-error` as unused, - // > so this TS directive must be removed. - // > However, to maintain compatibility with React 18 types during CI testing, - // > we had to instead use `@ts-ignore`. + // > Semantically, `@ts-expect-error` would be the right choice here: + // > it would fail under React 18 types and be unused under React 19 types. + // > However, when running with React 19 types, TypeScript reports that + // > `@ts-expect-error` is unused, which causes unwanted noise in CI. + // > To avoid those unused-directive diagnostics while still supporting + // > both React 18 and React 19 typings, we pragmatically use `@ts-ignore`, + // > acknowledging that it suppresses any real type errors at this site. // // eslint-disable-next-line @typescript-eslint/ban-ts-comment, @typescript-eslint/prefer-ts-expect-error // @ts-ignore From a970da661a11c8541a384e697601945e37fce113 Mon Sep 17 00:00:00 2001 From: Fai <4016742+aicest@users.noreply.github.com> Date: Sun, 21 Dec 2025 00:40:04 +0800 Subject: [PATCH 3/3] Apply suggestion from @Copilot Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- types/test.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/types/test.tsx b/types/test.tsx index 4316f92c..03b31d3f 100644 --- a/types/test.tsx +++ b/types/test.tsx @@ -264,7 +264,7 @@ 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"` + // 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"`. render(null, { // This option is intended to type-check successfully with React 19 types // but to fail (produce a type error) with React 18 types.