Bugsnag-js: [@bugsnag/plugin-react] createErrorBoundary() type

Created on 24 May 2020  路  4Comments  路  Source: bugsnag/bugsnag-js

Using TS 3.9.3, with

export const ErrorBoundary = Bugsnag.getPlugin("react")?.createErrorBoundary(React)

I get this error:

JSX element type 'ErrorBoundary' does not have any construct or call signatures.
ts(2604)

Capture d'e虂cran 2020-05-24 21 50 55

Most helpful comment

Ok, as I was trying to make a reproduction example, I realized that it's because createErrorBoundary() can return undefined, as clearly mentioned in the doc, my bad, so I should test for the existence of its return value.

const children = (
  <UserProvider>
    <App />
  </UserProvider>
)
return ErrorBoundary ? (
  <ErrorBoundary FallbackComponent={ErrorComponent}>{children}</ErrorBoundary>
) : (
  children
)

Sorry for the false alarm!

Also it would be cool to export the BugsnagErrorBoundary and BugsnagPluginReactResult types.

In particular, I would like to write this:

const plugin = Bugsnag.getPlugin("react") as BugsnagPluginReactResult
export const ErrorBoundary = plugin.createErrorBoundary()

Because I know the plugin exists, and this would simplify the use of the boundary since it wouldn't be "possibly undefined"

All 4 comments

Hi @antoinerousseau

Can you confirm which version of bugsnag-js you're using? The syntax above was only introduced in v7.1.0, so wouldn't be expected to work on earlier versions.

Yes I'm talking about v7.1.0

Hi @antoinerousseau

I don't get that error using typescript 3.9.3 and bugsnag-js 7.1.0. Can you share a complete reproduction example including all of your Bugsnag initialization code?

Ok, as I was trying to make a reproduction example, I realized that it's because createErrorBoundary() can return undefined, as clearly mentioned in the doc, my bad, so I should test for the existence of its return value.

const children = (
  <UserProvider>
    <App />
  </UserProvider>
)
return ErrorBoundary ? (
  <ErrorBoundary FallbackComponent={ErrorComponent}>{children}</ErrorBoundary>
) : (
  children
)

Sorry for the false alarm!

Also it would be cool to export the BugsnagErrorBoundary and BugsnagPluginReactResult types.

In particular, I would like to write this:

const plugin = Bugsnag.getPlugin("react") as BugsnagPluginReactResult
export const ErrorBoundary = plugin.createErrorBoundary()

Because I know the plugin exists, and this would simplify the use of the boundary since it wouldn't be "possibly undefined"

Was this page helpful?
0 / 5 - 0 ratings

Related issues

killia15 picture killia15  路  6Comments

mdonjones picture mdonjones  路  5Comments

rafmst picture rafmst  路  3Comments

darkyndy picture darkyndy  路  4Comments

waynebloss picture waynebloss  路  3Comments