Before Rxjs 6 we could do:
interface TypeA {
payload: any;
}
source$.pipe(
withLatestFrom(source2$, (source1: TypeA, source2: TypeB) =>
({ payload: source1.payload, source2 }) ),
)
We could, in the resultSelector method arguments, add proper types for source1
and source2
, passed along within the constructed object here.
But now we must do the following:
source$.pipe(
withLatestFrom(source2$),
map(([source1, source2]) => ({ source1, source2 }) ),
)
Doing so we are unable to add type on source1 and source2 within array argument. The typing is then lost and IDE doesn't suggest .payload
on source1
for example.
How to be able, using the new syntax, to add proper typing with array arguments?
You can add it like you would a tuple:
source$.pipe(
withLatestFrom(source2$),
map(([source1, source2]: [TypeA, TypeB]) => ({ source1, source2 }) ),
)
Although I am surprised you don't get typing automatically on it, I thought it did propagate them...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With