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 additional type safety for unhandledRejection #7719

Open
KevinGrandon opened this issue May 13, 2019 · 4 comments

Comments

Projects
None yet
3 participants
@KevinGrandon
Copy link
Contributor

commented May 13, 2019

Flow version: 0.98.1

Expected behavior

Process methods which listen for unhandledRejection should have additional type information. The argument should be mixed or similar, forcing the user to refine it.

Actual behavior

Anything can pass through the callback to unhandledRejection, including non-Error objects. Perhaps by default the type could be mixed?

  • Reproducible code:
// This code produces no errors in Flow, can it?
process.once('unhandledRejection', async e => {
  return e + 1;
});

Hello, not sure if something like this is possible, but it would definitely help prevent bugs if so.

@dsainati1

This comment has been minimized.

Copy link
Contributor

commented May 24, 2019

This can probably be done via overloading the definition for once in the libdefs to be more specific when the argument is 'unhandledRejection'. I would be happy to accept a PR for this.

@goodmind

This comment has been minimized.

Copy link
Collaborator

commented May 24, 2019

I think there was some bug if you overload string literals

@dsainati1

This comment has been minimized.

Copy link
Contributor

commented May 24, 2019

We do this all the time in the libdefs (see dom.js for a few examples) so I think it should definitely be possible here.

@KevinGrandon

This comment has been minimized.

Copy link
Contributor Author

commented May 24, 2019

I threw together something in #7761, but not sure if this is what we had in mind, also not able to run tests yet locally. I'll try again in the future, or someone can feel free to steal it. Thanks for chiming in.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.