rxjs icon indicating copy to clipboard operation
rxjs copied to clipboard

distintUntilChanged: new overload missing in bundle

Open angelaki opened this issue 1 year ago • 2 comments

Describe the bug

Definition of the new overload

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

is not generated in the bunde (rxjs/dist/types/internal/operators/distinctUntilChanged.d.ts)

Expected behavior

Have it with the other ones:

import { MonoTypeOperatorFunction } from '../types';
export declare function distinctUntilChanged<T>(comparator?: (previous: T, current: T) => boolean): MonoTypeOperatorFunction<T>;
export declare function distinctUntilChanged<T, K>(comparator: (previous: K, current: K) => boolean, keySelector: (value: T) => K): MonoTypeOperatorFunction<T>;
//# sourceMappingURL=distinctUntilChanged.d.ts.map

Reproduction code

No response

Reproduction URL

No response

Version

7.8.1

Environment

No response

Additional context

No response

angelaki avatar May 23 '24 11:05 angelaki

I am facing the same problem

conblem avatar Jun 26 '24 11:06 conblem

If you analyze the source you will see

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

the first overload is just the comparator, the second one is the comparator and the key selector which means you can have two objects as T and property keys as K, which would be returned by the second argument which is the keySelector function.

The third overload is the implementation The implementation signature must also be compatible with the overload signatures so in this case it is having a default value of identity which is a function returning the argument

export function identity<T>(x: T): T {
  return x;
}

So in this case you don't need it actually And also that's how typescript work.

Official typescript

` Again, the signature used to write the function body can’t be “seen” from the outside.

The signature of the implementation is not visible from the outside. When writing an overloaded function, you should always have two or more signatures above the implementation of the function.

` Myself i would have the K as keyof T so that non existent keys are not passed but that would mess up the overloading.

al-mart avatar Aug 01 '24 04:08 al-mart