Skip to content
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

reduce declares overloads in the wrong order causing spurious type errors #2339

Closed
aluanhaddad opened this issue Feb 7, 2017 · 2 comments
Closed
Labels
TS Issues and PRs related purely to TypeScript issues

Comments

@aluanhaddad
Copy link
Contributor

RxJS version: 5.1.0

Code to reproduce:

Expected behavior:
Code using reduce with a different seed type from the element type of the observable type checks correctly, resolving the type of the seed from the second type argument, R, in the overload set.
Actual behavior:
The overload set of the reduce operator is incorrect. The declarations are in the wrong order of specificity with respect to the types of their arguments and their type argument count.

export function reduce<T>(this: Observable<T>, accumulator: (acc: T, value: T, index: number) => T, seed?: T): Observable<T>;
export function reduce<T>(this: Observable<T>, accumulator: (acc: T[], value: T, index: number) => T[], seed?: T[]): Observable<T[]>;
export function reduce<T, R>(this: Observable<T>, accumulator: (acc: R, value: T, index: number) => R, seed?: R): Observable<R>;

Additional information:
I came across this bug when looking at a stackoverflow question
http://stackoverflow.com/q/42080580/1915893
The overloads need to be declared in the reverse of their current order. Specifically, the first of the three signatures needs to be the last and the last needs to be the first.

@kwonoj kwonoj added the TS Issues and PRs related purely to TypeScript issues label Feb 7, 2017
@aluanhaddad
Copy link
Contributor Author

Closing in favor of #2338

@lock
Copy link

lock bot commented Jun 6, 2018

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@lock lock bot locked as resolved and limited conversation to collaborators Jun 6, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
TS Issues and PRs related purely to TypeScript issues
Projects
None yet
Development

No branches or pull requests

2 participants