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

Add types #52

Open
SimenB opened this issue Oct 27, 2020 · 3 comments
Open

Add types #52

SimenB opened this issue Oct 27, 2020 · 3 comments

Comments

@SimenB
Copy link

SimenB commented Oct 27, 2020

https://nodejs.org/api/util.html#util_util_types

They work cross-realm (at least for Error coming from a new vm.Context). Not sure if it's worth it for you to work cross-realm, but just doing instanceof should work OK as a shim, think?

@ljharb
Copy link
Member

ljharb commented Oct 27, 2020

It should be 100% doable in most cases, i have tons of npm packages to handle most of them in a cross-realm way. https://npmjs.com/~inspect-js

@SimenB
Copy link
Author

SimenB commented Oct 27, 2020

Oh, nice! I'm specifically after a an error check as we gave a bunch of ugly duck typing in Jest to figure out if we have an error instance or not. But I'm hesitant to add utils usage in case it makes it harder to use parts of Jets in the browsers.

Do you have a package for Error (i.e. util.types.isNativeError)? Quick searching in the link you posted didn't find it, sorry if I missed something obvious. If so I'd love to use that and not worry about if it is shimmed by this package if people attempt to use e.g. expect or something in the browser

@ljharb
Copy link
Member

ljharb commented Oct 27, 2020

No, unfortunately there is no JavaScript way to robustly identify a native Error - instanceof Error is the best you can do.

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

No branches or pull requests

2 participants