-
Notifications
You must be signed in to change notification settings - Fork 3k
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
fromEventPattern() should not magically return different results based on arguments.length #4736
Comments
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 |
Maybe with all of the functions that do this ( So, let's say your It's an idea. Of course, we'd need to wait a long time to introduce this, because it's a breaking change. |
Core Team Notes: Punting this change to version 8. We can't do this at this stage of the v7 release. This will also give us time to come up with a solid design for how to handle this. |
Bug Report
Current Behavior
fromEventPattern
currently checksargs.length
and if it's 1, emits the first item, otherwise it emits an array of all:rxjs/src/internal/observable/fromEventPattern.ts
Line 153 in d3e7e3f
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 differentargs.length
and would result in one case in the emission of an array[undefined]
and in the other case inundefined
, 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, andresultSelector
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, theresultSelector
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 ormap
it to just the first parameter if desired.Environment
The text was updated successfully, but these errors were encountered: