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

removeEventListener does not allow reusing addEventListenerOptions #19368

Closed
HolgerJeromin opened this issue Oct 20, 2017 · 4 comments
Closed
Labels
Domain: lib.d.ts The issue relates to the different libraries shipped with TypeScript Needs More Info The issue still hasn't been fully clarified

Comments

@HolgerJeromin
Copy link
Contributor

TypeScript Version: 2.5

Right now EventTarget.removeEventListener is defined with the precise definition from the Spec (without passive). But I and MDN would suggest to use the exact parameter you used at addEventListener.

unless you have specific reasons otherwise, it's probably wise to use the same values used for the call to addEventListener() when calling removeEventListener().

ref #14196 #18136

@mhegazy
Copy link
Contributor

mhegazy commented Oct 20, 2017

The spec seems to be clear that remove does not accept passive: https://dom.spec.whatwg.org/#ref-for-dom-eventtarget-removeeventlistener%E2%91%A0

I would say we should follow the spec, unless there is a strong reason why not to.

@mhegazy mhegazy added Needs More Info The issue still hasn't been fully clarified Domain: lib.d.ts The issue relates to the different libraries shipped with TypeScript labels Oct 20, 2017
@HolgerJeromin
Copy link
Contributor Author

The Browser does/must not use passive. Yes.
But are more rich dictionaries are/should be disallowed?

@kitsonk
Copy link
Contributor

kitsonk commented Oct 23, 2017

Excess properties are allowed when the object is not fresh. When it is fresh, objects are restricted. It is intentional to help identify errors. So yes, in certain situations, subtype dictionaries can be assigned to supertypes.

const options: AddEventListenerOptions = {
    passive: true
}

declare const target: EventTarget;

const listener = () => { };

target.addEventListener('click', listener, options);
target.removeEventListener('click', listener, options); // Works fine
target.removeEventListener('click', listener, {
    passive: true // object is fresh, therefore checked for excess properties
                  // Object literal may only specify known properties, and 'passive' 
                  // does not exist in type 'boolean | EventListenerOptions'.
});

@HolgerJeromin
Copy link
Contributor Author

@kitsonk
Wow. I never recognized this difference!
This is exactly what i want! Thanks a lot.

@microsoft microsoft locked and limited conversation to collaborators Jun 14, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Domain: lib.d.ts The issue relates to the different libraries shipped with TypeScript Needs More Info The issue still hasn't been fully clarified
Projects
None yet
Development

No branches or pull requests

3 participants