Skip to content

fix: fix typing of distinctUntilChanged to allow comparator to be undefined #7550

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions packages/rxjs/spec/operators/distinctUntilChanged-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,18 @@ describe('distinctUntilChanged', () => {
});
});

it('should allow passing undefined as comparator', () => {
testScheduler.run(({ hot, expectObservable, expectSubscriptions }) => {
const e1 = hot(' --a--b--|', { a: 2, b: 4 });
const e1subs = ' ^-------!';
const expected = '--a-----|';
const keySelector = (x: number) => x % 2;

expectObservable(e1.pipe(distinctUntilChanged(undefined, keySelector))).toBe(expected, { a: 2 });
expectSubscriptions(e1.subscriptions).toBe(e1subs);
});
});

it('should raise error when keySelector throws', () => {
testScheduler.run(({ hot, expectObservable, expectSubscriptions }) => {
const e1 = hot(' --a--b--c--d--e--f--|');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { Observable, operate } from '@rxjs/observable';

export function distinctUntilChanged<T>(comparator?: (previous: T, current: T) => boolean): MonoTypeOperatorFunction<T>;
export function distinctUntilChanged<T, K>(
comparator: (previous: K, current: K) => boolean,
comparator: ((previous: K, current: K) => boolean) | undefined,
keySelector: (value: T) => K
): MonoTypeOperatorFunction<T>;

Expand Down