From d43952cae3b1ee4da88b25a5186e698f0d53a0d6 Mon Sep 17 00:00:00 2001 From: Abhijeet Prasad Date: Thu, 16 Feb 2023 11:10:32 +0100 Subject: [PATCH 1/2] fix(react): Make fallback render types more accurate --- packages/react/src/errorboundary.tsx | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/packages/react/src/errorboundary.tsx b/packages/react/src/errorboundary.tsx index 7e68416a67ce..c7a029a6c920 100644 --- a/packages/react/src/errorboundary.tsx +++ b/packages/react/src/errorboundary.tsx @@ -13,8 +13,8 @@ export const UNKNOWN_COMPONENT = 'unknown'; export type FallbackRender = (errorData: { error: Error; - componentStack: string | null; - eventId: string | null; + componentStack: string; + eventId: string; resetError(): void; }) => React.ReactElement; @@ -138,7 +138,14 @@ class ErrorBoundary extends React.Component Date: Thu, 16 Feb 2023 11:38:04 +0100 Subject: [PATCH 2/2] use state to describe types --- packages/react/src/errorboundary.tsx | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/packages/react/src/errorboundary.tsx b/packages/react/src/errorboundary.tsx index c7a029a6c920..1553028195a2 100644 --- a/packages/react/src/errorboundary.tsx +++ b/packages/react/src/errorboundary.tsx @@ -48,11 +48,17 @@ export type ErrorBoundaryProps = { beforeCapture?(scope: Scope, error: Error | null, componentStack: string | null): void; }; -type ErrorBoundaryState = { - componentStack: React.ErrorInfo['componentStack'] | null; - error: Error | null; - eventId: string | null; -}; +type ErrorBoundaryState = + | { + componentStack: null; + error: null; + eventId: null; + } + | { + componentStack: React.ErrorInfo['componentStack']; + error: Error; + eventId: string; + }; const INITIAL_STATE = { componentStack: null, @@ -133,18 +139,16 @@ class ErrorBoundary extends React.Component