rollbar / rollbar.js

Error tracking and logging from Javascript to Rollbar

Home Page:https://docs.rollbar.com/docs/javascript

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

ErrorBoundary props for TS

Meetyouafter opened this issue · comments

commented

Hello, everyone!
My App is React with TS latest version.
I wanted to pass level, errorMessage , extra to ErrorBoundary like this:

const level = (error: Error, info: ErrorInfo): LEVEL => error instanceof TypeError ? LEVEL_ERROR : LEVEL_WARN;

but i get an error: Type '(error: any, info: any) => "warn" | "error"' is not assignable to type 'LEVEL | (() => LEVEL) | undefined'.

I changed type in index.d.ts in @rollbar package with pass (error, info) to this values in ErrorBoundaryProps, but it doesn't help for me.

I did something wrong or what?

Hi @Meetyouafter ,

I think the bug is in the index.d.ts definition. You changed it to level?: LEVEL | ((error: any, info: any) => LEVEL); and it didn't work?

commented

yes, i changed level in ErrorBoundaryProps to this level?: LEVEL | ((error: Error, errorInfo: ErrorInfo) => LEVEL);

if i use it
const level = (error: Error, info: ErrorInfo): LEVEL => error instanceof TypeError ? LEVEL_ERROR : LEVEL_WARN;
i have
failed: (error, info) => error instanceof TypeError ? _rollbar_react__WEBPACK_IMPORTED_MODULE_0__.LEVEL_ERROR : _rollbar_react__WEBPACK_IMPORTED_MODULE_0__.LEVEL_WARN is not a valid level setting for Rollbar

if i use it
const level = (error: Error, info: ErrorInfo): LEVEL => error instanceof TypeError ? 'error' : 'warn';
i have
Uncaught Error: Invariant failed: (error, info) => error instanceof TypeError ? 'error' : 'warn' is not a valid level setting for Rollbar

Errors from tiny-invariant and i can't find resolve

Thank you, that's helpful. I'll follow up shortly.