Skip to content

Wrong removeEventListener() parameters #174

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

Closed
tkrotoff opened this issue Dec 6, 2016 · 3 comments
Closed

Wrong removeEventListener() parameters #174

tkrotoff opened this issue Dec 6, 2016 · 3 comments

Comments

@tkrotoff
Copy link
Contributor

tkrotoff commented Dec 6, 2016

Current definition:

addEventListener(type: string, listener?: EventListenerOrEventListenerObject, useCapture?: boolean): void;
removeEventListener(type: string, listener?: EventListenerOrEventListenerObject, useCapture?: boolean): void;

Should be something like:

interface AddEventListenerOptions {
  capture?: boolean;
  once?: boolean;
  passive?: boolean;
}

interface RemoveEventListenerOptions {
  capture?: boolean;
  passive?: boolean;
}

interface EventTarget {
  addEventListener(type: string, listener: EventListenerOrEventListenerObject, options?: AddEventListenerOptions): void;
  addEventListener(type: string, listener: EventListenerOrEventListenerObject, useCapture?: boolean): void;
  removeEventListener(type: string, listener: EventListenerOrEventListenerObject, useCapture?: boolean): void;
  removeEventListener(type: string, listener: EventListenerOrEventListenerObject, options?: RemoveEventListenerOptions): void;
}

listener is mandatory.

See addEventListener and removeEventListener:

target.addEventListener(type, listener[, options]);
target.addEventListener(type, listener[, useCapture]);

target.removeEventListener(type, listener[, options]);
target.removeEventListener(type, listener[, useCapture]);

Example:

var listener = function() {
  console.log('Hello!');
}

document.body.addEventListener('click', listener);

document.body.click(); // Hello!

document.body.removeEventListener('click'); // BOOM! =>
/* Under Chrome 55:
Uncaught TypeError: Failed to execute 'removeEventListener' on 'EventTarget': 2 arguments required, but only 1 present.
*/

/* Under Firefox 47
TypeError: Not enough arguments to EventTarget.removeEventListener.
*/

document.body.addEventListener('click'); // BOOM! =>
/* Under Chrome 55:
Uncaught TypeError: Failed to execute 'addEventListener' on 'EventTarget': 2 arguments required, but only 1 present.
*/
@saschanaz
Copy link
Contributor

Partially fixed by #224 but the listener is still optional.

@saschanaz
Copy link
Contributor

Has been fixed since then.

@github-actions close

@github-actions
Copy link
Contributor

Closing because @saschanaz is one of the code-owners of this repository.

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

2 participants