Skip to content

Simplify / fix HTMLCollection overrides #2079

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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
88 changes: 41 additions & 47 deletions baselines/dom.generated.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10035,7 +10035,7 @@ interface Document extends Node, DocumentOrShadowRoot, FontFaceSource, GlobalEve
*
* [MDN Reference](https://developer.mozilla.org/docs/Web/API/Document/anchors)
*/
readonly anchors: HTMLCollectionOf<HTMLAnchorElement>;
readonly anchors: HTMLCollection<HTMLAnchorElement>;
/**
* The **`applets`** property of the Document returns an empty HTMLCollection.
* @deprecated
Expand Down Expand Up @@ -10140,7 +10140,7 @@ interface Document extends Node, DocumentOrShadowRoot, FontFaceSource, GlobalEve
*
* [MDN Reference](https://developer.mozilla.org/docs/Web/API/Document/embeds)
*/
readonly embeds: HTMLCollectionOf<HTMLEmbedElement>;
readonly embeds: HTMLCollection<HTMLEmbedElement>;
/**
* **`fgColor`** gets/sets the foreground color, or text color, of the current document.
* @deprecated
Expand All @@ -10153,7 +10153,7 @@ interface Document extends Node, DocumentOrShadowRoot, FontFaceSource, GlobalEve
*
* [MDN Reference](https://developer.mozilla.org/docs/Web/API/Document/forms)
*/
readonly forms: HTMLCollectionOf<HTMLFormElement>;
readonly forms: HTMLCollection<HTMLFormElement>;
/**
* The **`fragmentDirective`** read-only property of the Document interface returns the FragmentDirective for the current document.
*
Expand Down Expand Up @@ -10190,7 +10190,7 @@ interface Document extends Node, DocumentOrShadowRoot, FontFaceSource, GlobalEve
*
* [MDN Reference](https://developer.mozilla.org/docs/Web/API/Document/images)
*/
readonly images: HTMLCollectionOf<HTMLImageElement>;
readonly images: HTMLCollection<HTMLImageElement>;
/**
* The **`Document.implementation`** property returns a A DOMImplementation object.
*
Expand Down Expand Up @@ -10221,7 +10221,7 @@ interface Document extends Node, DocumentOrShadowRoot, FontFaceSource, GlobalEve
*
* [MDN Reference](https://developer.mozilla.org/docs/Web/API/Document/links)
*/
readonly links: HTMLCollectionOf<HTMLAnchorElement | HTMLAreaElement>;
readonly links: HTMLCollection<HTMLAnchorElement | HTMLAreaElement>;
/**
* The **`Document.location`** read-only property returns a and provides methods for changing that URL and loading another URL.
*
Expand Down Expand Up @@ -10253,7 +10253,7 @@ interface Document extends Node, DocumentOrShadowRoot, FontFaceSource, GlobalEve
*
* [MDN Reference](https://developer.mozilla.org/docs/Web/API/Document/plugins)
*/
readonly plugins: HTMLCollectionOf<HTMLEmbedElement>;
readonly plugins: HTMLCollection<HTMLEmbedElement>;
/**
* The **`Document.readyState`** property describes the loading state of the document.
*
Expand All @@ -10278,7 +10278,7 @@ interface Document extends Node, DocumentOrShadowRoot, FontFaceSource, GlobalEve
*
* [MDN Reference](https://developer.mozilla.org/docs/Web/API/Document/scripts)
*/
readonly scripts: HTMLCollectionOf<HTMLScriptElement>;
readonly scripts: HTMLCollection<HTMLScriptElement>;
/**
* The **`scrollingElement`** read-only property of the scrolls the document.
*
Expand Down Expand Up @@ -10525,7 +10525,7 @@ interface Document extends Node, DocumentOrShadowRoot, FontFaceSource, GlobalEve
*
* [MDN Reference](https://developer.mozilla.org/docs/Web/API/Document/getElementsByClassName)
*/
getElementsByClassName(classNames: string): HTMLCollectionOf<Element>;
getElementsByClassName(classNames: string): HTMLCollection;
/**
* The **`getElementsByName()`** method of the Document object returns a NodeList Collection of elements with a given `name` attribute in the document.
*
Expand All @@ -10537,21 +10537,21 @@ interface Document extends Node, DocumentOrShadowRoot, FontFaceSource, GlobalEve
*
* [MDN Reference](https://developer.mozilla.org/docs/Web/API/Document/getElementsByTagName)
*/
getElementsByTagName<K extends keyof HTMLElementTagNameMap>(qualifiedName: K): HTMLCollectionOf<HTMLElementTagNameMap[K]>;
getElementsByTagName<K extends keyof SVGElementTagNameMap>(qualifiedName: K): HTMLCollectionOf<SVGElementTagNameMap[K]>;
getElementsByTagName<K extends keyof MathMLElementTagNameMap>(qualifiedName: K): HTMLCollectionOf<MathMLElementTagNameMap[K]>;
getElementsByTagName<K extends keyof HTMLElementTagNameMap>(qualifiedName: K): HTMLCollection<HTMLElementTagNameMap[K]>;
getElementsByTagName<K extends keyof SVGElementTagNameMap>(qualifiedName: K): HTMLCollection<SVGElementTagNameMap[K]>;
getElementsByTagName<K extends keyof MathMLElementTagNameMap>(qualifiedName: K): HTMLCollection<MathMLElementTagNameMap[K]>;
/** @deprecated */
getElementsByTagName<K extends keyof HTMLElementDeprecatedTagNameMap>(qualifiedName: K): HTMLCollectionOf<HTMLElementDeprecatedTagNameMap[K]>;
getElementsByTagName(qualifiedName: string): HTMLCollectionOf<Element>;
getElementsByTagName<K extends keyof HTMLElementDeprecatedTagNameMap>(qualifiedName: K): HTMLCollection<HTMLElementDeprecatedTagNameMap[K]>;
getElementsByTagName(qualifiedName: string): HTMLCollection;
/**
* Returns a list of elements with the given tag name belonging to the given namespace.
*
* [MDN Reference](https://developer.mozilla.org/docs/Web/API/Document/getElementsByTagNameNS)
*/
getElementsByTagNameNS(namespaceURI: "http://www.w3.org/1999/xhtml", localName: string): HTMLCollectionOf<HTMLElement>;
getElementsByTagNameNS(namespaceURI: "http://www.w3.org/2000/svg", localName: string): HTMLCollectionOf<SVGElement>;
getElementsByTagNameNS(namespaceURI: "http://www.w3.org/1998/Math/MathML", localName: string): HTMLCollectionOf<MathMLElement>;
getElementsByTagNameNS(namespace: string | null, localName: string): HTMLCollectionOf<Element>;
getElementsByTagNameNS(namespaceURI: "http://www.w3.org/1999/xhtml", localName: string): HTMLCollection<HTMLElement>;
getElementsByTagNameNS(namespaceURI: "http://www.w3.org/2000/svg", localName: string): HTMLCollection<SVGElement>;
getElementsByTagNameNS(namespaceURI: "http://www.w3.org/1998/Math/MathML", localName: string): HTMLCollection<MathMLElement>;
getElementsByTagNameNS(namespace: string | null, localName: string): HTMLCollection;
/**
* The **`getSelection()`** method of the Document interface returns the Selection object associated with this document, representing the range of text selected by the user, or the current position of the caret.
*
Expand Down Expand Up @@ -11159,27 +11159,27 @@ interface Element extends Node, ARIAMixin, Animatable, ChildNode, NonDocumentTyp
*
* [MDN Reference](https://developer.mozilla.org/docs/Web/API/Element/getElementsByClassName)
*/
getElementsByClassName(classNames: string): HTMLCollectionOf<Element>;
getElementsByClassName(classNames: string): HTMLCollection;
/**
* The **`Element.getElementsByTagName()`** method returns a live All descendants of the specified element are searched, but not the element itself.
*
* [MDN Reference](https://developer.mozilla.org/docs/Web/API/Element/getElementsByTagName)
*/
getElementsByTagName<K extends keyof HTMLElementTagNameMap>(qualifiedName: K): HTMLCollectionOf<HTMLElementTagNameMap[K]>;
getElementsByTagName<K extends keyof SVGElementTagNameMap>(qualifiedName: K): HTMLCollectionOf<SVGElementTagNameMap[K]>;
getElementsByTagName<K extends keyof MathMLElementTagNameMap>(qualifiedName: K): HTMLCollectionOf<MathMLElementTagNameMap[K]>;
getElementsByTagName<K extends keyof HTMLElementTagNameMap>(qualifiedName: K): HTMLCollection<HTMLElementTagNameMap[K]>;
getElementsByTagName<K extends keyof SVGElementTagNameMap>(qualifiedName: K): HTMLCollection<SVGElementTagNameMap[K]>;
getElementsByTagName<K extends keyof MathMLElementTagNameMap>(qualifiedName: K): HTMLCollection<MathMLElementTagNameMap[K]>;
/** @deprecated */
getElementsByTagName<K extends keyof HTMLElementDeprecatedTagNameMap>(qualifiedName: K): HTMLCollectionOf<HTMLElementDeprecatedTagNameMap[K]>;
getElementsByTagName(qualifiedName: string): HTMLCollectionOf<Element>;
getElementsByTagName<K extends keyof HTMLElementDeprecatedTagNameMap>(qualifiedName: K): HTMLCollection<HTMLElementDeprecatedTagNameMap[K]>;
getElementsByTagName(qualifiedName: string): HTMLCollection;
/**
* The **`Element.getElementsByTagNameNS()`** method returns a live HTMLCollection of elements with the given tag name belonging to the given namespace.
*
* [MDN Reference](https://developer.mozilla.org/docs/Web/API/Element/getElementsByTagNameNS)
*/
getElementsByTagNameNS(namespaceURI: "http://www.w3.org/1999/xhtml", localName: string): HTMLCollectionOf<HTMLElement>;
getElementsByTagNameNS(namespaceURI: "http://www.w3.org/2000/svg", localName: string): HTMLCollectionOf<SVGElement>;
getElementsByTagNameNS(namespaceURI: "http://www.w3.org/1998/Math/MathML", localName: string): HTMLCollectionOf<MathMLElement>;
getElementsByTagNameNS(namespace: string | null, localName: string): HTMLCollectionOf<Element>;
getElementsByTagNameNS(namespaceURI: "http://www.w3.org/1999/xhtml", localName: string): HTMLCollection<HTMLElement>;
getElementsByTagNameNS(namespaceURI: "http://www.w3.org/2000/svg", localName: string): HTMLCollection<SVGElement>;
getElementsByTagNameNS(namespaceURI: "http://www.w3.org/1998/Math/MathML", localName: string): HTMLCollection<MathMLElement>;
getElementsByTagNameNS(namespace: string | null, localName: string): HTMLCollection;
/**
* The **`getHTML()`** method of the Element interface is used to serialize an element's DOM to an HTML string.
*
Expand Down Expand Up @@ -13688,7 +13688,7 @@ declare var HTMLCanvasElement: {
*
* [MDN Reference](https://developer.mozilla.org/docs/Web/API/HTMLCollection)
*/
interface HTMLCollectionBase {
interface HTMLCollectionBase<E extends Element = Element, N = never> {
/**
* The **`HTMLCollection.length`** property returns the number of items in a HTMLCollection.
*
Expand All @@ -13700,30 +13700,24 @@ interface HTMLCollectionBase {
*
* [MDN Reference](https://developer.mozilla.org/docs/Web/API/HTMLCollection/item)
*/
item(index: number): Element | null;
[index: number]: Element;
item(index: number): E | null;
[index: number]: E;
}

interface HTMLCollection extends HTMLCollectionBase {
interface HTMLCollection<E extends Element = Element, N = never> extends HTMLCollectionBase {
/**
* The **`namedItem()`** method of the HTMLCollection interface returns the first Element in the collection whose `id` or `name` attribute match the specified name, or `null` if no element matches.
*
* [MDN Reference](https://developer.mozilla.org/docs/Web/API/HTMLCollection/namedItem)
*/
namedItem(name: string): Element | null;
namedItem(name: string): E | N | null;
}

declare var HTMLCollection: {
prototype: HTMLCollection;
new(): HTMLCollection;
};

interface HTMLCollectionOf<T extends Element> extends HTMLCollectionBase {
item(index: number): T | null;
namedItem(name: string): T | null;
[index: number]: T;
}

/**
* The **`HTMLDListElement`** interface provides special properties (beyond those of the regular HTMLElement interface it also has available to it by inheritance) for manipulating definition list (dl) elements.
*
Expand Down Expand Up @@ -13782,7 +13776,7 @@ interface HTMLDataListElement extends HTMLElement {
*
* [MDN Reference](https://developer.mozilla.org/docs/Web/API/HTMLDataListElement/options)
*/
readonly options: HTMLCollectionOf<HTMLOptionElement>;
readonly options: HTMLCollection<HTMLOptionElement>;
addEventListener<K extends keyof HTMLElementEventMap>(type: K, listener: (this: HTMLDataListElement, ev: HTMLElementEventMap[K]) => any, options?: boolean | AddEventListenerOptions): void;
addEventListener(type: string, listener: EventListenerOrEventListenerObject, options?: boolean | AddEventListenerOptions): void;
removeEventListener<K extends keyof HTMLElementEventMap>(type: K, listener: (this: HTMLDataListElement, ev: HTMLElementEventMap[K]) => any, options?: boolean | EventListenerOptions): void;
Expand Down Expand Up @@ -14284,7 +14278,7 @@ declare var HTMLFontElement: {
*
* [MDN Reference](https://developer.mozilla.org/docs/Web/API/HTMLFormControlsCollection)
*/
interface HTMLFormControlsCollection extends HTMLCollectionBase {
interface HTMLFormControlsCollection extends HTMLCollection<Element, RadioNodeList> {
/**
* The **`HTMLFormControlsCollection.namedItem()`** method returns the RadioNodeList or the Element in the collection whose `name` or `id` match the specified name, or `null` if no node matches.
*
Expand Down Expand Up @@ -15522,7 +15516,7 @@ interface HTMLMapElement extends HTMLElement {
*
* [MDN Reference](https://developer.mozilla.org/docs/Web/API/HTMLMapElement/areas)
*/
readonly areas: HTMLCollection;
readonly areas: HTMLCollection<HTMLAreaElement>;
/**
* The **`name`** property of the HTMLMapElement represents the unique name `<map>` element.
*
Expand Down Expand Up @@ -16296,7 +16290,7 @@ declare var HTMLOptionElement: {
*
* [MDN Reference](https://developer.mozilla.org/docs/Web/API/HTMLOptionsCollection)
*/
interface HTMLOptionsCollection extends HTMLCollectionOf<HTMLOptionElement> {
interface HTMLOptionsCollection extends HTMLCollection<HTMLOptionElement> {
/**
* The **`length`** property of the HTMLOptionsCollection interface returns the number of option elements in the collection.
*
Expand Down Expand Up @@ -16752,7 +16746,7 @@ interface HTMLSelectElement extends HTMLElement {
*
* [MDN Reference](https://developer.mozilla.org/docs/Web/API/HTMLSelectElement/selectedOptions)
*/
readonly selectedOptions: HTMLCollectionOf<HTMLOptionElement>;
readonly selectedOptions: HTMLCollection<HTMLOptionElement>;
/**
* The **`size`** property of the HTMLSelectElement interface specifies the number of options, or rows, that should be visible at one time.
*
Expand Down Expand Up @@ -17255,7 +17249,7 @@ interface HTMLTableElement extends HTMLElement {
*
* [MDN Reference](https://developer.mozilla.org/docs/Web/API/HTMLTableElement/rows)
*/
readonly rows: HTMLCollectionOf<HTMLTableRowElement>;
readonly rows: HTMLCollection<HTMLTableRowElement>;
/**
* The **`HTMLTableElement.rules`** property indicates which cell borders to render in the table.
* @deprecated
Expand All @@ -17275,7 +17269,7 @@ interface HTMLTableElement extends HTMLElement {
*
* [MDN Reference](https://developer.mozilla.org/docs/Web/API/HTMLTableElement/tBodies)
*/
readonly tBodies: HTMLCollectionOf<HTMLTableSectionElement>;
readonly tBodies: HTMLCollection<HTMLTableSectionElement>;
/**
* The **`HTMLTableElement.tFoot`** property represents the `null` if there is no such element.
*
Expand Down Expand Up @@ -17393,7 +17387,7 @@ interface HTMLTableRowElement extends HTMLElement {
*
* [MDN Reference](https://developer.mozilla.org/docs/Web/API/HTMLTableRowElement/cells)
*/
readonly cells: HTMLCollectionOf<HTMLTableCellElement>;
readonly cells: HTMLCollection<HTMLTableCellElement>;
/**
* The **`ch`** property of the HTMLTableRowElement interface does nothing.
* @deprecated
Expand Down Expand Up @@ -17482,7 +17476,7 @@ interface HTMLTableSectionElement extends HTMLElement {
*
* [MDN Reference](https://developer.mozilla.org/docs/Web/API/HTMLTableSectionElement/rows)
*/
readonly rows: HTMLCollectionOf<HTMLTableRowElement>;
readonly rows: HTMLCollection<HTMLTableRowElement>;
/**
* The **`vAlign`** property of the HTMLTableSectionElement interface is a string indicating how to vertically align text in a thead, tbody or tfoot table section.
* @deprecated
Expand Down
6 changes: 1 addition & 5 deletions baselines/dom.iterable.generated.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,14 +146,10 @@ interface HTMLAllCollection {
[Symbol.iterator](): ArrayIterator<Element>;
}

interface HTMLCollectionBase {
interface HTMLCollectionBase<E extends Element = Element, N = never> {
[Symbol.iterator](): ArrayIterator<Element>;
}

interface HTMLCollectionOf<T extends Element> {
[Symbol.iterator](): ArrayIterator<T>;
}

interface HTMLFormElement {
[Symbol.iterator](): ArrayIterator<Element>;
}
Expand Down
2 changes: 2 additions & 0 deletions baselines/serviceworker.generated.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11489,6 +11489,8 @@ type GLsizei = number;
type GLsizeiptr = number;
type GLuint = number;
type GLuint64 = number;
/** @deprecated */
type HTMLCollectionOf<T extends Element> = HTMLCollection<T>;
type HashAlgorithmIdentifier = AlgorithmIdentifier;
type HeadersInit = [string, string][] | Record<string, string> | Headers;
type IDBValidKey = number | string | Date | BufferSource | IDBValidKey[];
Expand Down
2 changes: 2 additions & 0 deletions baselines/sharedworker.generated.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11178,6 +11178,8 @@ type GLsizei = number;
type GLsizeiptr = number;
type GLuint = number;
type GLuint64 = number;
/** @deprecated */
type HTMLCollectionOf<T extends Element> = HTMLCollection<T>;
type HashAlgorithmIdentifier = AlgorithmIdentifier;
type HeadersInit = [string, string][] | Record<string, string> | Headers;
type IDBValidKey = number | string | Date | BufferSource | IDBValidKey[];
Expand Down
Loading
Loading