Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ErrorBoundary props for TS #1112

Open
Meetyouafter opened this issue Jul 12, 2023 · 3 comments
Open

ErrorBoundary props for TS #1112

Meetyouafter opened this issue Jul 12, 2023 · 3 comments
Labels

Comments

@Meetyouafter
Copy link

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?

@waltjones
Copy link
Contributor

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?

@Meetyouafter
Copy link
Author

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

@waltjones
Copy link
Contributor

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

@mudetroit mudetroit added the bug label Nov 14, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants