@@ -36,13 +36,13 @@ export type ErrorBoundaryProps = {
3636 */
3737 fallback ?: React . ReactElement | FallbackRender | undefined ;
3838 /** Called when the error boundary encounters an error */
39- onError ?: ( ( error : unknown , componentStack : string , eventId : string ) => void ) | undefined ;
39+ onError ?: ( ( error : unknown , componentStack : string | undefined , eventId : string ) => void ) | undefined ;
4040 /** Called on componentDidMount() */
4141 onMount ?: ( ( ) => void ) | undefined ;
4242 /** Called if resetError() is called from the fallback render props function */
43- onReset ?: ( ( error : unknown , componentStack : string | null , eventId : string | null ) => void ) | undefined ;
43+ onReset ?: ( ( error : unknown , componentStack : string | null | undefined , eventId : string | null ) => void ) | undefined ;
4444 /** Called on componentWillUnmount() */
45- onUnmount ?: ( ( error : unknown , componentStack : string | null , eventId : string | null ) => void ) | undefined ;
45+ onUnmount ?: ( ( error : unknown , componentStack : string | null | undefined , eventId : string | null ) => void ) | undefined ;
4646 /** Called before the error is captured by Sentry, allows for you to add tags or context using the scope */
4747 beforeCapture ?: ( ( scope : Scope , error : unknown , componentStack : string | undefined ) => void ) | undefined ;
4848} ;
@@ -97,16 +97,19 @@ class ErrorBoundary extends React.Component<ErrorBoundaryProps, ErrorBoundarySta
9797
9898 public componentDidCatch ( error : unknown , errorInfo : React . ErrorInfo ) : void {
9999 const { componentStack } = errorInfo ;
100+ // TODO(v9): Remove this check and type `componentStack` to be React.ErrorInfo['componentStack'].
101+ const passedInComponentStack : string | undefined = componentStack == null ? undefined : componentStack ;
102+
100103 const { beforeCapture, onError, showDialog, dialogOptions } = this . props ;
101104 withScope ( scope => {
102105 if ( beforeCapture ) {
103- beforeCapture ( scope , error , componentStack ) ;
106+ beforeCapture ( scope , error , passedInComponentStack ) ;
104107 }
105108
106109 const eventId = captureReactException ( error , errorInfo , { mechanism : { handled : ! ! this . props . fallback } } ) ;
107110
108111 if ( onError ) {
109- onError ( error , componentStack , eventId ) ;
112+ onError ( error , passedInComponentStack , eventId ) ;
110113 }
111114 if ( showDialog ) {
112115 this . _lastEventId = eventId ;
@@ -186,7 +189,6 @@ function withErrorBoundary<P extends Record<string, any>>(
186189 WrappedComponent : React . ComponentType < P > ,
187190 errorBoundaryOptions : ErrorBoundaryProps ,
188191) : React . FC < P > {
189- // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
190192 const componentDisplayName = WrappedComponent . displayName || WrappedComponent . name || UNKNOWN_COMPONENT ;
191193
192194 const Wrapped : React . FC < P > = ( props : P ) => (
@@ -195,12 +197,13 @@ function withErrorBoundary<P extends Record<string, any>>(
195197 </ ErrorBoundary >
196198 ) ;
197199
198- // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
199200 Wrapped . displayName = `errorBoundary(${ componentDisplayName } )` ;
200201
201202 // Copy over static methods from Wrapped component to Profiler HOC
202203 // See: https://reactjs.org/docs/higher-order-components.html#static-methods-must-be-copied-over
203- hoistNonReactStatics ( Wrapped , WrappedComponent ) ;
204+ // Need to set type to any because of hoist-non-react-statics typing
205+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
206+ hoistNonReactStatics ( Wrapped , WrappedComponent as any ) ;
204207 return Wrapped ;
205208}
206209
0 commit comments