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

distintUntilChanged: new overload missing in bundle #7475

Open
angelaki opened this issue May 23, 2024 · 2 comments
Open

distintUntilChanged: new overload missing in bundle #7475

angelaki opened this issue May 23, 2024 · 2 comments

Comments

@angelaki
Copy link

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

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

@conblem
Copy link

conblem commented Jun 26, 2024

I am facing the same problem

@al-mart
Copy link

al-mart commented Aug 1, 2024

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants