-
Notifications
You must be signed in to change notification settings - Fork 13.1k
Description
TypeScript Version: master
Search Terms:
MediaQueryList addListener
addListener
MediaQueryList
Code
const listener = window.matchMedia("(max-width: 1000px)");
const handler = () => {};
listener.addListener(handler);
listener.removeListener(handler);
Expected behavior:
addListener
and removeListener
are "valid" signatures to invoke
Actual behavior:
addListener
and removeListener
are deprecated
Related Issues:
None
Notes:
This document describes the MediaQueryList
interface: https://drafts.csswg.org/cssom-view/#dom-mediaquerylist-addlistener
It doesn't list addListener
and removeListener
as deprecated, does not give an indication that they will be deprecated in the future, it also does not say that you should use addEventListener
and removeEventListener
instead.
It did say that addListener
and removeListener
are direct aliases.
Source:
https://github.com/microsoft/TypeScript/blob/master/lib/lib.dom.d.ts#L10018
Why would I bring this up:
Because Safari and Internet Explorer do not support addEventListener
and removeEventListener
, but they do support addListener
and removeListener
.
Because addListener
and removeListener
are deprecated it means that people are more likely to use the alternatives without looking at the issues with doing so.
A lot of examples with the usage of MediaQueryList
show addListener
and removeListener
usage, even the documentation on MDN: https://developer.mozilla.org/en-US/docs/Web/API/MediaQueryList#Examples