Skip to content

ref(utils): Use type predicates for isError and isString #4757

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

Merged

Conversation

lobsterkatie
Copy link
Member

This restores part of the work done in #4124, which then got reverted in #4149. The problem there was the predicates for DOMError and DOMException, both of which only exist in a browser context. This restores the predicates for isError and isString, which should be safe, because both Error and string exist in both browser and node contexts.

@github-actions
Copy link
Contributor

size-limit report

Path Base Size (1379591) Current Size Change
@sentry/browser - ES5 CDN Bundle (gzipped + minified) 19.49 KB 19.49 KB -0.02% 🔽
@sentry/browser - ES5 CDN Bundle (minified) 62.17 KB 62.17 KB 0%
@sentry/browser - ES6 CDN Bundle (gzipped + minified) 18.12 KB 18.11 KB -0.01% 🔽
@sentry/browser - ES6 CDN Bundle (minified) 55.5 KB 55.5 KB 0%
@sentry/browser - Webpack (gzipped + minified) 22.6 KB 22.6 KB 0%
@sentry/browser - Webpack (minified) 79.21 KB 79.21 KB 0%
@sentry/react - Webpack (gzipped + minified) 22.63 KB 22.63 KB 0%
@sentry/nextjs Client - Webpack (gzipped + minified) 47.6 KB 47.6 KB 0%
@sentry/browser + @sentry/tracing - ES5 CDN Bundle (gzipped + minified) 25.37 KB 25.36 KB -0.01% 🔽
@sentry/browser + @sentry/tracing - ES6 CDN Bundle (gzipped + minified) 23.72 KB 23.72 KB -0.01% 🔽

@lobsterkatie lobsterkatie requested review from a team, Lms24 and AbhiPrasad and removed request for a team March 23, 2022 09:49
Copy link
Member

@Lms24 Lms24 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This LGTM and I learned about type predicates - cool feature. Are there places where we could then get rid of unnecessary casts? I just made a quick search and found this here as an example

const value = error[key];
extraErrorInfo[key] = isError(value) ? (value as Error).toString() : value;
}

where - if I understood type predicates correctly - we could probably get rid of as Error in the ternary operator's then branch. I tried to do it and it compiled without errors. However, it seems like eslint needs an adjustment because it highlights it as an error in (my) VSCode.

Anyway, I guess this could just as good be a separate PR for someone to pick up once we get to it.

@lobsterkatie
Copy link
Member Author

lobsterkatie commented Mar 23, 2022

No, you're totally right. If you look at the original PR, I actually went through and found all the places which could be fixed, because I was making the type predicates change for its own sake. Here I just happened upon it as part of other work and didn't follow up with the repo-wide check. I'll go port them from the other PR. Thanks for keeping me honest. 🙂

UPDATE: Found a bunch of other spots which could use the same kind of cleanup, so I'm going to merge this and throw them all into a separate PR.

@lobsterkatie lobsterkatie merged commit 944af2a into master Mar 23, 2022
@lobsterkatie lobsterkatie deleted the kmclb-use-type-predicates-for-isError-and-isString branch March 23, 2022 21:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants