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

fix(fromEvent): match targets properly; fix result selector type #6208

Merged
merged 5 commits into from Apr 9, 2021

Conversation

cartant
Copy link
Collaborator

@cartant cartant commented Apr 4, 2021

Description:

This PR fixes some problems with fromEvent:

  • The interfaces used to match targets need to use methods instead of props. Otherwise, extends behaves in an unintended manner and the types won't match.
  • There is a signature that takes only the target and the event name, so the optional qualifiers on the other signatures are redundant.
  • If the resultSelector returns T, the target's type should not be FromEventTarget<T>.

The typing of fromEvent could be improved, but I think the first step is to fix these problems. The next would be to replace the FromEventTarget type with separate signatures.

Related issue (if exists): Nope

@cartant cartant requested a review from benlesh April 4, 2021 13:08
@cartant cartant changed the title fix(fromEvent): match targets properly fix(fromEvent): match targets properly; fix result selector type Apr 4, 2021
@benlesh
Copy link
Member

benlesh commented Apr 9, 2021

The interfaces used to match targets need to use methods instead of props. Otherwise, extends behaves in an unintended manner and the types won't match.

WTF. 🙄 lol

@@ -70,11 +70,11 @@ export interface AddEventListenerOptions extends EventListenerOptions {

export function fromEvent<T>(target: FromEventTarget<T>, eventName: string): Observable<T>;
/** @deprecated resultSelector no longer supported, pipe to map instead */
export function fromEvent<T>(target: FromEventTarget<T>, eventName: string, resultSelector?: (...args: any[]) => T): Observable<T>;
export function fromEvent<T>(target: FromEventTarget<T>, eventName: string, options?: EventListenerOptions): Observable<T>;
export function fromEvent<T>(target: FromEventTarget<any>, eventName: string, resultSelector: (...args: any[]) => T): Observable<T>;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems to make sense. We're loosing up the type here, because really it's the T that matters. However, part of me feels like we should undeprecate this signature (as discussed in #5824), and in that case, we should try to get the types correct that are being passed to the result selector. I suppose we can do that in another pass though.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah. That's something that can be done after it's split into separate signatures. ATM, FromEventTarget makes the function look simpler than it really is and the T is really only applicable to some of the signatures.

@benlesh benlesh merged commit 8412c73 into ReactiveX:master Apr 9, 2021
@cartant cartant deleted the cartant/fix-from-event branch April 18, 2021 02:52
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

Successfully merging this pull request may close these issues.

None yet

2 participants