-
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
fix(scan): fixed declarations to properly support different return types #4598
Conversation
bf45b63
to
b084779
Compare
The build is failing✨ Good work on this PR so far! ✨ Unfortunately, the Travis CI build is failing as of bf45b63. Here's the output:
|
Pull Request Test Coverage Report for Build 8405
💛 - Coveralls |
compat/operator/reduce.ts
Outdated
@@ -2,9 +2,8 @@ import { Observable } from 'rxjs'; | |||
import { reduce as higherOrderReduce } from 'rxjs/operators'; | |||
|
|||
/* tslint:disable:max-line-length */ | |||
export function reduce<T, R>(this: Observable<T>, accumulator: (acc: R, value: T, index: number) => R, seed?: R): Observable<R>; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think the seed can be optional if the accumulator has a different type the the source elements. If a seed is not specified, my understanding is that the first element will be used, instead. That means that the initial accumulator value will be a T
and not an R
as indicator by the call signature.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You're correct... adding tests and updating.
@@ -6,9 +6,9 @@ import { OperatorFunction, MonoTypeOperatorFunction } from '../types'; | |||
import { pipe } from '../util/pipe'; | |||
|
|||
/* tslint:disable:max-line-length */ | |||
export function reduce<T, R>(accumulator: (acc: R, value: T, index: number) => R, seed: R): OperatorFunction<T, R>; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So there's this messed up scenario I think we need to test for:
of(1).pipe(reduce((acc, value, i) => i === 0 ? [] : [..value], { seed: 'LOL' }))
The problem is that acc
gets typed wrong.
I'm sure that scan
has the same issue.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So we assume that seed
and ReturnType<typeof accumulator>
are the same type, if they differ we get an error because accumulator returns an invalid value. Thoughts?
this solves an issue where if you would reduce over `T` you can get `T` out reliably, but you could not get out `R` in anyway without manually typing the reduce method call
Would love to see this merged as it is creating quite the nuisance while migrating from |
…pes (ReactiveX#4598) this solves an issue where if you would reduce over `T` you can get `T` out reliably, but you could not get out `R` in anyway without manually typing the reduce method call
Description:
This solves an issue where if you would reduce over
T
you can getT
out reliably, but you couldnot get out
R
in anyway without manually typing the reduce method callRelated issue (if exists):
#4086
cc @cartant