-
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
More typed arguments in withLatestFrom #5221
Comments
I'm in two minds about adding more signatures, at this stage. Version 7 is currently being worked on and the focus of that version is improving the types - as we'll no longer be constrained by having to support TypeScript 2.8. See #5066 On of the principal aims will be to solve this needs-more-args problem once and for all - by having signatures that support an arbitrary number of arguments. That said, if |
Thanks for the explanation and pointing to the existing issue. Hopefully it will get better in v7. However I don't think having more arguments is "edge-case-y" - it really depends on complexity of the application. In my case I have multiple UI components collecting input from user across a wizard-like steps. I use |
Well, I'm not saying it's wrong. I'm just saying that it's an edge case and I think this being the first time the issue has been raised - AFAICT - in a number of years attests to that. Anyway, if you want, you can take advantage of TypeScript's declaration merging to add signatures with more typed parameters in userland. You should be able to add as many as you need - while you wait for v7 - by doing something like this: declare module "rxjs/internal/operators/withLatestFrom" {
export declare function withLatestFrom<
T,
O2 extends ObservableInput<any>,
O3 extends ObservableInput<any>,
O4 extends ObservableInput<any>,
O5 extends ObservableInput<any>,
O6 extends ObservableInput<any>,
O7 extends ObservableInput<any>
>(
v2: O2, v3: O3, v4: O4, v5: O5, v6: O6, v7: O7
): OperatorFunction<T, [
T,
ObservedValueOf<O2>,
ObservedValueOf<O3>,
ObservedValueOf<O4>,
ObservedValueOf<O5>,
ObservedValueOf<O6>,
ObservedValueOf<O7>
]>;
} |
This is a perfect workaround for now. Thanks! |
Update: I ended up copying all of the signatures from |
I would not have put it in a |
I've had time to try it and this seems to be fine for me - with RxJS import { ObservableInput, ObservedValueOf, of, OperatorFunction } from "rxjs";
import { withLatestFrom } from "rxjs/operators";
declare module "rxjs/internal/operators/withLatestFrom" {
export function withLatestFrom<
T,
O2 extends ObservableInput<any>,
O3 extends ObservableInput<any>,
O4 extends ObservableInput<any>,
O5 extends ObservableInput<any>,
O6 extends ObservableInput<any>,
O7 extends ObservableInput<any>
>(
v2: O2,
v3: O3,
v4: O4,
v5: O5,
v6: O6,
v7: O7
): OperatorFunction<
T,
[
T,
ObservedValueOf<O2>,
ObservedValueOf<O3>,
ObservedValueOf<O4>,
ObservedValueOf<O5>,
ObservedValueOf<O6>,
ObservedValueOf<O7>
]
>;
}
const source = of(1).pipe(
withLatestFrom(of(2), of(3), of(4), of(5), of(6), of(7))
); |
Closing this, as it's going to be addressed in v7 and there is a userland workaround. if you have problems with the workaround, feel free to comment in this issue, though. |
Feature Request
Is your feature request related to a problem? Please describe.
Currently the max number of supported arguments in
withLatestFrom
is 5. Adding more than that results inany
types.Describe the solution you'd like
Add more function exports to the
withLatestFrom.ts
.I'll gladly create a PR if above is an accepted solution.
The text was updated successfully, but these errors were encountered: