Skip to content

Commit 8631772

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

File tree

2 files changed

+73
-0
lines changed

2 files changed

+73
-0
lines changed

types/react-dom/canary.d.ts

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

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

152179
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)