-
Notifications
You must be signed in to change notification settings - Fork 13.1k
Description
Currently, the following DOM methods has a return type definition of NodeList, but the type of nodes returned is actually always Element:
getElementsByClassName
getElementsByTagNameNS
getElementsByTagName(name: string)
getElementsByName
msElementsFromPoint
msElementsFromRect
As a result, a cast to Element is required before any method of Element can be used. To remove the need of the cast, I suggest changing their return type definition to NodeListOf<Element>.
Also, there are some HTML DOM properties (e.g. document.forms) having a return type definition of HTMLCollection, but HTMLCollection does not extend NodeListOf<HTMLElement>. That leads to some difficulties in creating a method that takes a list of elements. I suggest changing HTMLCollection to extend NodeListOf<HTMLElement>.
Finally, should a List<T> interface with the following definition be created, such that Array<T>, NodeList, NodeListOf<HTMLElement> and HTMLCollection all extend to List<T>?
interface List {
length: number;
[index: number]: T;
}