You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I acknowledge that issues using this template may be closed without further explanation at the maintainer's discretion.
Comment
I am looking for an official explanation why TS accepts Promise as void. Playground
When I provide a higher-order function that accepts a callback () => void I do not want user's to inject a function () => Promise<void> because I do not handle the rejection case of the Promise inside my higher-order function which might lead to an unhandled promise rejection.
Same goes from the other direction if by accident I put a callback () => Promise<void> into an higher-order function that only accepts () => void I would like to be informed that the higher-order function will not handle the Promise rejection correctly because it does not expect a Promise to be returned by the callback but void.
But I assume there was a thought process behind the decision to accept Promise as void but I could not find in the official reason.
The text was updated successfully, but these errors were encountered:
This is working as intended. A callback returning void means "can be whatever, I don't care". If the user wants to return a promise, so be it. When they want to return an object, so be it.
Same goes from the other direction if by accident I put a callback () => Promise<void> into an higher-order function that only accepts () => void I would like to be informed that the higher-order function will not handle the Promise rejection correctly because it does not expect a Promise to be returned by the callback but void.
Typescript-eslint has a rule for this if you really want to ensure you're not using this behaviour.
Acknowledgement
Comment
I am looking for an official explanation why TS accepts Promise as void.
Playground
When I provide a higher-order function that accepts a callback
() => void
I do not want user's to inject a function() => Promise<void>
because I do not handle the rejection case of the Promise inside my higher-order function which might lead to an unhandled promise rejection.Same goes from the other direction if by accident I put a callback
() => Promise<void>
into an higher-order function that only accepts() => void
I would like to be informed that the higher-order function will not handle the Promise rejection correctly because it does not expect a Promise to be returned by the callback but void.But I assume there was a thought process behind the decision to accept Promise as void but I could not find in the official reason.
The text was updated successfully, but these errors were encountered: