Skip to content

Commit 7a63d62

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

File tree

2 files changed

+74
-0
lines changed

2 files changed

+74
-0
lines changed

types/react-dom/canary.d.ts

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

148+
interface RootOptions {
149+
formState?: ReactFormState | null;
150+
onUncaughtError?:
151+
| ((error: unknown, errorInfo: { componentStack?: string | undefined }) => void)
152+
| undefined;
153+
onCaughtError?:
154+
| ((
155+
error: unknown,
156+
errorInfo: {
157+
componentStack?: string | undefined;
158+
errorBoundary?: React.Component<unknown> | undefined;
159+
},
160+
) => void)
161+
| undefined;
162+
}
163+
148164
interface HydrationOptions {
149165
formState?: ReactFormState | null;
166+
onUncaughtError?:
167+
| ((error: unknown, errorInfo: { componentStack?: string | undefined }) => void)
168+
| undefined;
169+
onCaughtError?:
170+
| ((
171+
error: unknown,
172+
errorInfo: {
173+
componentStack?: string | undefined;
174+
errorBoundary?: React.Component<unknown> | undefined;
175+
},
176+
) => void)
177+
| undefined;
150178
}
151179

152180
interface DO_NOT_USE_OR_YOU_WILL_BE_FIRED_EXPERIMENTAL_CREATE_ROOT_CONTAINERS {

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

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,4 +265,50 @@ 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+
// @ts-expect-error -- only on onCaughtError
301+
errorInfo.errorBoundary;
302+
},
303+
onCaughtError: (error, errorInfo) => {
304+
// $ExpectType unknown
305+
error;
306+
// $ExpectType string | undefined
307+
errorInfo.componentStack;
308+
// @ts-expect-error -- only on onRecoverableError
309+
errorInfo.digest;
310+
// $ExpectType Component<unknown, {}, any> | undefined
311+
errorInfo.errorBoundary;
312+
},
313+
});
268314
}

0 commit comments

Comments
 (0)