functions
functions copied to clipboard
Fix events.subscribe types: returns either an async or promise function
Returning unknown
from events.subscribe
, as the types do today, sucks if you're writing tests:
This PR attempts to address this by tweaking the return type of subscribe
, which is conditional based on what kind of event handler function you pass into subscribe
:
-
If you pass an async function,
subscribe
returns an async function. - If you pass it a regular function that accepts two parameters, the second parameter being a callback, it returns a regular function that takes three parameters, the last being a callback too.
With these changes, now my tests are tidier with less IDE complaints. With an async handler the result looks like:
.. and using a callback interface, too:
No matter which style of handler you pass, at least in the context of my tests, now my IDE knows that I am dealing with functions - even the right kinds to boot!