Skip to content

Update HTMLCollection and Add HTMLCollectionOf<T extends Element> #78

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

Merged
merged 5 commits into from
Mar 24, 2016
Merged
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
40 changes: 23 additions & 17 deletions baselines/dom.generated.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2308,11 +2308,11 @@ interface Document extends Node, GlobalEventHandlers, NodeSelector, DocumentEven
/**
* Retrieves a collection of all a objects that have a name and/or id property. Objects in this collection are in HTML source order.
*/
anchors: HTMLCollection;
anchors: HTMLCollectionOf<HTMLAnchorElement>;
/**
* Retrieves a collection of all applet objects in the document.
*/
applets: HTMLCollection;
applets: HTMLCollectionOf<HTMLAppletElement>;
/**
* Deprecated. Sets or retrieves a value that indicates the background color behind the object.
*/
Expand Down Expand Up @@ -2360,23 +2360,23 @@ interface Document extends Node, GlobalEventHandlers, NodeSelector, DocumentEven
/**
* Retrieves a collection of all embed objects in the document.
*/
embeds: HTMLCollection;
embeds: HTMLCollectionOf<HTMLEmbedElement>;
/**
* Sets or gets the foreground (text) color of the document.
*/
fgColor: string;
/**
* Retrieves a collection, in source order, of all form objects in the document.
*/
forms: HTMLCollection;
forms: HTMLCollectionOf<HTMLFormElement>;
fullscreenElement: Element;
fullscreenEnabled: boolean;
head: HTMLHeadElement;
hidden: boolean;
/**
* Retrieves a collection, in source order, of img objects in the document.
*/
images: HTMLCollection;
images: HTMLCollectionOf<HTMLImageElement>;
/**
* Gets the implementation object of the current document.
*/
Expand All @@ -2396,7 +2396,7 @@ interface Document extends Node, GlobalEventHandlers, NodeSelector, DocumentEven
/**
* Retrieves a collection of all a objects that specify the href property and all area objects in the document.
*/
links: HTMLCollection;
links: HTMLCollectionOf<HTMLAnchorElement | HTMLAreaElement>;
/**
* Contains information about the current URL.
*/
Expand Down Expand Up @@ -2711,7 +2711,7 @@ interface Document extends Node, GlobalEventHandlers, NodeSelector, DocumentEven
onwaiting: (ev: Event) => any;
onwebkitfullscreenchange: (ev: Event) => any;
onwebkitfullscreenerror: (ev: Event) => any;
plugins: HTMLCollection;
plugins: HTMLCollectionOf<HTMLEmbedElement>;
pointerLockElement: Element;
/**
* Retrieves a value that indicates the current state of the object.
Expand All @@ -2728,7 +2728,7 @@ interface Document extends Node, GlobalEventHandlers, NodeSelector, DocumentEven
/**
* Retrieves a collection of all script objects in the document.
*/
scripts: HTMLCollection;
scripts: HTMLCollectionOf<HTMLScriptElement>;
scrollingElement: Element;
/**
* Retrieves a collection of styleSheet objects representing the style sheets that correspond to each instance of a link or style object in the document.
Expand Down Expand Up @@ -4455,7 +4455,7 @@ interface HTMLCollection {
/**
* Retrieves an object from various collections.
*/
item(nameOrIndex?: any, optionalIndex?: any): Element;
item(index: number): Element;
/**
* Retrieves a select object or an object from an options collection.
*/
Expand All @@ -4478,7 +4478,7 @@ declare var HTMLDListElement: {
}

interface HTMLDataListElement extends HTMLElement {
options: HTMLCollection;
options: HTMLCollectionOf<HTMLOptionElement>;
}

declare var HTMLDataListElement: {
Expand Down Expand Up @@ -6773,7 +6773,7 @@ interface HTMLSelectElement extends HTMLElement {
* Sets or retrieves the name of the object.
*/
name: string;
options: HTMLCollection;
options: HTMLCollectionOf<HTMLOptionElement>;
/**
* When present, marks an element that can't be submitted without a value.
*/
Expand All @@ -6782,7 +6782,7 @@ interface HTMLSelectElement extends HTMLElement {
* Sets or retrieves the index of the selected option in a select object.
*/
selectedIndex: number;
selectedOptions: HTMLCollection;
selectedOptions: HTMLCollectionOf<HTMLOptionElement>;
/**
* Sets or retrieves the number of rows in the list box.
*/
Expand Down Expand Up @@ -7035,7 +7035,7 @@ interface HTMLTableElement extends HTMLElement {
/**
* Sets or retrieves the number of horizontal rows contained in the object.
*/
rows: HTMLCollection;
rows: HTMLCollectionOf<HTMLTableRowElement>;
/**
* Sets or retrieves which dividing lines (inner borders) are displayed.
*/
Expand All @@ -7047,7 +7047,7 @@ interface HTMLTableElement extends HTMLElement {
/**
* Retrieves a collection of all tBody objects in the table. Objects in this collection are in source order.
*/
tBodies: HTMLCollection;
tBodies: HTMLCollectionOf<HTMLTableSectionElement>;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not HTMLTableBodyElement?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I followed the return type of the following functions:

createElement(tagName: "tbody"): HTMLTableSectionElement;
getElementsByTagName(tagname: "tbody"): NodeListOf<HTMLTableSectionElement>;
createTBody(): HTMLTableSectionElement;

/**
* Retrieves the tFoot object of the table.
*/
Expand Down Expand Up @@ -7126,7 +7126,7 @@ interface HTMLTableRowElement extends HTMLElement, HTMLTableAlignment {
/**
* Retrieves a collection of all cells in the table row.
*/
cells: HTMLCollection;
cells: HTMLCollectionOf<HTMLTableDataCellElement | HTMLTableHeaderCellElement>;
/**
* Sets or retrieves the height of the object.
*/
Expand All @@ -7148,7 +7148,7 @@ interface HTMLTableRowElement extends HTMLElement, HTMLTableAlignment {
* Creates a new cell in the table row, and adds the cell to the cells collection.
* @param index Number that specifies where to insert the cell in the tr. The default value is -1, which appends the new cell to the end of the cells collection.
*/
insertCell(index?: number): HTMLTableCellElement;
insertCell(index?: number): HTMLTableDataCellElement;
addEventListener(type: string, listener: EventListenerOrEventListenerObject, useCapture?: boolean): void;
}

Expand All @@ -7165,7 +7165,7 @@ interface HTMLTableSectionElement extends HTMLElement, HTMLTableAlignment {
/**
* Sets or retrieves the number of horizontal rows contained in the object.
*/
rows: HTMLCollection;
rows: HTMLCollectionOf<HTMLTableRowElement>;
/**
* Removes the specified row (tr) from the element and from the rows collection.
* @param index Number that specifies the zero-based position in the rows collection of the row to remove.
Expand Down Expand Up @@ -13623,6 +13623,12 @@ interface NodeListOf<TNode extends Node> extends NodeList {
[index: number]: TNode;
}

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

interface BlobPropertyBag {
type?: string;
endings?: string;
Expand Down
27 changes: 26 additions & 1 deletion inputfiles/addedTypes.json
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,29 @@
}
]
},
{
"kind": "interface",
"name": "HTMLCollectionOf<T extends Element>",
"flavor": "Web",
"extends": "HTMLCollection",
"methods": [
{
"name": "item",
"signatures": ["item(index: number): T"]
},
{
"name": "namedItem",
"signatures": ["namedItem(name: string): T"]
}
],
"indexer": [
{
"signatures": [
"[index: number]: T"
]
}
]
},
{
"kind": "interface",
"name": "BlobPropertyBag",
Expand Down Expand Up @@ -188,7 +211,9 @@
{
"kind": "indexer",
"interface": "HTMLCollection",
"signatures": ["[index: number]: Element"]
"signatures": [
"[index: number]: Element"
]
},
{
"kind": "signatureoverload",
Expand Down
94 changes: 92 additions & 2 deletions inputfiles/overridingTypes.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
[
{
"kind": "method",
"interface": "HTMLCollection",
"name": "item",
"signatures": ["item(index: number): Element"]
},
{
"kind": "method",
"interface": "IDBObjectStore",
Expand Down Expand Up @@ -103,6 +109,54 @@
"getElementsByName(elementName: string): NodeListOf<Element>"
]
},
{
"kind": "property",
"interface": "Document",
"name": "anchors",
"type": "HTMLCollectionOf<HTMLAnchorElement>"
},
{
"kind": "property",
"interface": "Document",
"name": "applets",
"type": "HTMLCollectionOf<HTMLAppletElement>"
},
{
"kind": "property",
"interface": "Document",
"name": "embeds",
"type": "HTMLCollectionOf<HTMLEmbedElement>"
},
{
"kind": "property",
"interface": "Document",
"name": "forms",
"type": "HTMLCollectionOf<HTMLFormElement>"
},
{
"kind": "property",
"interface": "Document",
"name": "images",
"type": "HTMLCollectionOf<HTMLImageElement>"
},
{
"kind": "property",
"interface": "Document",
"name": "links",
"type": "HTMLCollectionOf<HTMLAnchorElement | HTMLAreaElement>"
},
{
"kind": "property",
"interface": "Document",
"name": "plugins",
"type": "HTMLCollectionOf<HTMLEmbedElement>"
},
{
"kind": "property",
"interface": "Document",
"name": "scripts",
"type": "HTMLCollectionOf<HTMLScriptElement>"
},
{
"kind": "property",
"interface": "CanvasRenderingContext2D",
Expand Down Expand Up @@ -228,7 +282,19 @@
"kind": "property",
"interface": "HTMLSelectElement",
"name": "options",
"type": "HTMLCollection"
"type": "HTMLCollectionOf<HTMLOptionElement>"
},
{
"kind": "property",
"interface": "HTMLSelectElement",
"name": "selectedOptions",
"type": "HTMLCollectionOf<HTMLOptionElement>"
},
{
"kind": "property",
"interface": "HTMLDataListElement",
"name": "options",
"type": "HTMLCollectionOf<HTMLOptionElement>"
},
{
"kind": "property",
Expand Down Expand Up @@ -266,17 +332,41 @@
"name": "createCaption",
"signatures": ["createCaption(): HTMLTableCaptionElement"]
},
{
"kind": "property",
"interface": "HTMLTableElement",
"name": "rows",
"type": "HTMLCollectionOf<HTMLTableRowElement>"
},
{
"kind": "property",
"interface": "HTMLTableElement",
"name": "tBodies",
"type": "HTMLCollectionOf<HTMLTableSectionElement>"
},
{
"kind": "method",
"interface": "HTMLTableSectionElement",
"name": "insertRow",
"signatures": ["insertRow(index?: number): HTMLTableRowElement"]
},
{
"kind": "property",
"interface": "HTMLTableSectionElement",
"name": "rows",
"type": "HTMLCollectionOf<HTMLTableRowElement>"
},
{
"kind": "method",
"interface": "HTMLTableRowElement",
"name": "insertCell",
"signatures": ["insertCell(index?: number): HTMLTableCellElement"]
"signatures": ["insertCell(index?: number): HTMLTableDataCellElement"]
},
{
"kind": "property",
"interface": "HTMLTableRowElement",
"name": "cells",
"type": "HTMLCollectionOf<HTMLTableDataCellElement | HTMLTableHeaderCellElement>"
},
{
"kind": "method",
Expand Down