Current Behavior
fromEventPattern currently checks args.length and if it's 1, emits the first item, otherwise it emits an array of all:
This is problematic because it is not type safe and unpredictable.
It could be made slightly more type safe with a conditional type, but even then, if the parameter is optional TS would accept calling the listener with undefined or no parameter at all, which are different args.length and would result in one case in the emission of an array [undefined] and in the other case in undefined, which would not be checked by the type checker.
Checking arguments.length is generally considered bad practice.
What's worse is that you can't even reliably use resultSelector anymore to ensure it is always an array, because the magic switching is _always_ done first, and resultSelector is just a shortcut now that checks if the element is an array. Which means that if the listener was _actually_ called with an array as a single parameter, the resultSelector logic would _think_ it was instead called with multiple parameters and spread the array out.
Expected behavior
fromEventPattern() should just emit a tuple of all parameters. It's trivial to destructure that array or map it to just the first parameter if desired.
Environment
Yeah. I agree that this behaviour is not ideal. This is something that could be looked at for v7, but not for v6 where it would be a breaking change.
How about simply replacing e.length === 1 with e.length <= 1 for now? I'd call it a bug fix, not a breaking change.
Most helpful comment
Yeah. I agree that this behaviour is not ideal. This is something that could be looked at for v7, but not for v6 where it would be a breaking change.