Skip to content

Commit 67b6b76

Browse files
committed
[react-dom] Add types for onUncaughtError and onCaughtError
Types for facebook/react#28641
1 parent 212dfbf commit 67b6b76

2 files changed

Lines changed: 58 additions & 0 deletions

File tree

types/react-dom/canary.d.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,8 +145,22 @@ declare module "./client" {
145145
[REACT_FORM_STATE_SIGIL]: never;
146146
}
147147

148+
interface RootOptions {
149+
formState?: ReactFormState | null;
150+
onUncaughtError?: (error: unknown, errorInfo: { componentStack?: string | undefined }) => void;
151+
onCaughtError?: (
152+
error: unknown,
153+
errorInfo: { componentStack?: string | undefined; errorBoundary?: React.Component<unknown> | undefined },
154+
) => void;
155+
}
156+
148157
interface HydrationOptions {
149158
formState?: ReactFormState | null;
159+
onUncaughtError?: (error: unknown, errorInfo: { componentStack?: string | undefined }) => void;
160+
onCaughtError?: (
161+
error: unknown,
162+
errorInfo: { componentStack?: string | undefined; errorBoundary?: React.Component<unknown> | undefined },
163+
) => void;
150164
}
151165

152166
interface DO_NOT_USE_OR_YOU_WILL_BE_FIRED_EXPERIMENTAL_CREATE_ROOT_CONTAINERS {

types/react-dom/test/canary-tests.tsx

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,4 +265,48 @@ function formTest() {
265265
function createRoot(validContainer: Element | DocumentFragment | Document) {
266266
ReactDOMClient.createRoot(document);
267267
ReactDOMClient.createRoot(validContainer);
268+
269+
ReactDOMClient.createRoot(document, {
270+
onUncaughtError: (error, errorInfo) => {
271+
// $ExpectType unknown
272+
error;
273+
// $ExpectType string | undefined
274+
errorInfo.componentStack;
275+
// @ts-expect-error -- only on onRecoverableError
276+
errorInfo.digest;
277+
// @ts-expect-error -- only on onCaughtError
278+
errorInfo.errorBoundary;
279+
},
280+
onCaughtError: (error, errorInfo) => {
281+
// $ExpectType unknown
282+
error;
283+
// $ExpectType string | undefined
284+
errorInfo.componentStack;
285+
// @ts-expect-error -- only on onRecoverableError
286+
errorInfo.digest;
287+
// $ExpectType Component<unknown, {}, any> | undefined
288+
errorInfo.errorBoundary;
289+
},
290+
});
291+
292+
ReactDOMClient.hydrateRoot(document.body, null, {
293+
onUncaughtError: (error, errorInfo) => {
294+
// $ExpectType unknown
295+
error;
296+
// $ExpectType string | undefined
297+
errorInfo.componentStack;
298+
// @ts-expect-error -- only on onRecoverableError
299+
errorInfo.digest;
300+
},
301+
onCaughtError: (error, errorInfo) => {
302+
// $ExpectType unknown
303+
error;
304+
// $ExpectType string | undefined
305+
errorInfo.componentStack;
306+
// @ts-expect-error -- only on onRecoverableError
307+
errorInfo.digest;
308+
// $ExpectType Component<unknown, {}, any> | undefined
309+
errorInfo.errorBoundary;
310+
},
311+
});
268312
}

0 commit comments

Comments
 (0)