Skip to content

Commit 363eccd

Browse files
committed
Merge pull request #78 from FranklinWhale/master
Update HTMLCollection and Add HTMLCollectionOf<T extends Element>
2 parents 2c8a660 + fce7fa7 commit 363eccd

File tree

3 files changed

+141
-20
lines changed

3 files changed

+141
-20
lines changed

baselines/dom.generated.d.ts

Lines changed: 23 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2308,11 +2308,11 @@ interface Document extends Node, GlobalEventHandlers, NodeSelector, DocumentEven
23082308
/**
23092309
* Retrieves a collection of all a objects that have a name and/or id property. Objects in this collection are in HTML source order.
23102310
*/
2311-
anchors: HTMLCollection;
2311+
anchors: HTMLCollectionOf<HTMLAnchorElement>;
23122312
/**
23132313
* Retrieves a collection of all applet objects in the document.
23142314
*/
2315-
applets: HTMLCollection;
2315+
applets: HTMLCollectionOf<HTMLAppletElement>;
23162316
/**
23172317
* Deprecated. Sets or retrieves a value that indicates the background color behind the object.
23182318
*/
@@ -2360,23 +2360,23 @@ interface Document extends Node, GlobalEventHandlers, NodeSelector, DocumentEven
23602360
/**
23612361
* Retrieves a collection of all embed objects in the document.
23622362
*/
2363-
embeds: HTMLCollection;
2363+
embeds: HTMLCollectionOf<HTMLEmbedElement>;
23642364
/**
23652365
* Sets or gets the foreground (text) color of the document.
23662366
*/
23672367
fgColor: string;
23682368
/**
23692369
* Retrieves a collection, in source order, of all form objects in the document.
23702370
*/
2371-
forms: HTMLCollection;
2371+
forms: HTMLCollectionOf<HTMLFormElement>;
23722372
fullscreenElement: Element;
23732373
fullscreenEnabled: boolean;
23742374
head: HTMLHeadElement;
23752375
hidden: boolean;
23762376
/**
23772377
* Retrieves a collection, in source order, of img objects in the document.
23782378
*/
2379-
images: HTMLCollection;
2379+
images: HTMLCollectionOf<HTMLImageElement>;
23802380
/**
23812381
* Gets the implementation object of the current document.
23822382
*/
@@ -2396,7 +2396,7 @@ interface Document extends Node, GlobalEventHandlers, NodeSelector, DocumentEven
23962396
/**
23972397
* Retrieves a collection of all a objects that specify the href property and all area objects in the document.
23982398
*/
2399-
links: HTMLCollection;
2399+
links: HTMLCollectionOf<HTMLAnchorElement | HTMLAreaElement>;
24002400
/**
24012401
* Contains information about the current URL.
24022402
*/
@@ -2711,7 +2711,7 @@ interface Document extends Node, GlobalEventHandlers, NodeSelector, DocumentEven
27112711
onwaiting: (ev: Event) => any;
27122712
onwebkitfullscreenchange: (ev: Event) => any;
27132713
onwebkitfullscreenerror: (ev: Event) => any;
2714-
plugins: HTMLCollection;
2714+
plugins: HTMLCollectionOf<HTMLEmbedElement>;
27152715
pointerLockElement: Element;
27162716
/**
27172717
* Retrieves a value that indicates the current state of the object.
@@ -2728,7 +2728,7 @@ interface Document extends Node, GlobalEventHandlers, NodeSelector, DocumentEven
27282728
/**
27292729
* Retrieves a collection of all script objects in the document.
27302730
*/
2731-
scripts: HTMLCollection;
2731+
scripts: HTMLCollectionOf<HTMLScriptElement>;
27322732
scrollingElement: Element;
27332733
/**
27342734
* Retrieves a collection of styleSheet objects representing the style sheets that correspond to each instance of a link or style object in the document.
@@ -4455,7 +4455,7 @@ interface HTMLCollection {
44554455
/**
44564456
* Retrieves an object from various collections.
44574457
*/
4458-
item(nameOrIndex?: any, optionalIndex?: any): Element;
4458+
item(index: number): Element;
44594459
/**
44604460
* Retrieves a select object or an object from an options collection.
44614461
*/
@@ -4478,7 +4478,7 @@ declare var HTMLDListElement: {
44784478
}
44794479

44804480
interface HTMLDataListElement extends HTMLElement {
4481-
options: HTMLCollection;
4481+
options: HTMLCollectionOf<HTMLOptionElement>;
44824482
}
44834483

44844484
declare var HTMLDataListElement: {
@@ -6773,7 +6773,7 @@ interface HTMLSelectElement extends HTMLElement {
67736773
* Sets or retrieves the name of the object.
67746774
*/
67756775
name: string;
6776-
options: HTMLCollection;
6776+
options: HTMLCollectionOf<HTMLOptionElement>;
67776777
/**
67786778
* When present, marks an element that can't be submitted without a value.
67796779
*/
@@ -6782,7 +6782,7 @@ interface HTMLSelectElement extends HTMLElement {
67826782
* Sets or retrieves the index of the selected option in a select object.
67836783
*/
67846784
selectedIndex: number;
6785-
selectedOptions: HTMLCollection;
6785+
selectedOptions: HTMLCollectionOf<HTMLOptionElement>;
67866786
/**
67876787
* Sets or retrieves the number of rows in the list box.
67886788
*/
@@ -7035,7 +7035,7 @@ interface HTMLTableElement extends HTMLElement {
70357035
/**
70367036
* Sets or retrieves the number of horizontal rows contained in the object.
70377037
*/
7038-
rows: HTMLCollection;
7038+
rows: HTMLCollectionOf<HTMLTableRowElement>;
70397039
/**
70407040
* Sets or retrieves which dividing lines (inner borders) are displayed.
70417041
*/
@@ -7047,7 +7047,7 @@ interface HTMLTableElement extends HTMLElement {
70477047
/**
70487048
* Retrieves a collection of all tBody objects in the table. Objects in this collection are in source order.
70497049
*/
7050-
tBodies: HTMLCollection;
7050+
tBodies: HTMLCollectionOf<HTMLTableSectionElement>;
70517051
/**
70527052
* Retrieves the tFoot object of the table.
70537053
*/
@@ -7126,7 +7126,7 @@ interface HTMLTableRowElement extends HTMLElement, HTMLTableAlignment {
71267126
/**
71277127
* Retrieves a collection of all cells in the table row.
71287128
*/
7129-
cells: HTMLCollection;
7129+
cells: HTMLCollectionOf<HTMLTableDataCellElement | HTMLTableHeaderCellElement>;
71307130
/**
71317131
* Sets or retrieves the height of the object.
71327132
*/
@@ -7148,7 +7148,7 @@ interface HTMLTableRowElement extends HTMLElement, HTMLTableAlignment {
71487148
* Creates a new cell in the table row, and adds the cell to the cells collection.
71497149
* @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.
71507150
*/
7151-
insertCell(index?: number): HTMLTableCellElement;
7151+
insertCell(index?: number): HTMLTableDataCellElement;
71527152
addEventListener(type: string, listener: EventListenerOrEventListenerObject, useCapture?: boolean): void;
71537153
}
71547154

@@ -7165,7 +7165,7 @@ interface HTMLTableSectionElement extends HTMLElement, HTMLTableAlignment {
71657165
/**
71667166
* Sets or retrieves the number of horizontal rows contained in the object.
71677167
*/
7168-
rows: HTMLCollection;
7168+
rows: HTMLCollectionOf<HTMLTableRowElement>;
71697169
/**
71707170
* Removes the specified row (tr) from the element and from the rows collection.
71717171
* @param index Number that specifies the zero-based position in the rows collection of the row to remove.
@@ -13625,6 +13625,12 @@ interface NodeListOf<TNode extends Node> extends NodeList {
1362513625
[index: number]: TNode;
1362613626
}
1362713627

13628+
interface HTMLCollectionOf<T extends Element> extends HTMLCollection {
13629+
item(index: number): T;
13630+
namedItem(name: string): T;
13631+
[index: number]: T;
13632+
}
13633+
1362813634
interface BlobPropertyBag {
1362913635
type?: string;
1363013636
endings?: string;

inputfiles/addedTypes.json

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,29 @@
8787
}
8888
]
8989
},
90+
{
91+
"kind": "interface",
92+
"name": "HTMLCollectionOf<T extends Element>",
93+
"flavor": "Web",
94+
"extends": "HTMLCollection",
95+
"methods": [
96+
{
97+
"name": "item",
98+
"signatures": ["item(index: number): T"]
99+
},
100+
{
101+
"name": "namedItem",
102+
"signatures": ["namedItem(name: string): T"]
103+
}
104+
],
105+
"indexer": [
106+
{
107+
"signatures": [
108+
"[index: number]: T"
109+
]
110+
}
111+
]
112+
},
90113
{
91114
"kind": "interface",
92115
"name": "BlobPropertyBag",
@@ -188,7 +211,9 @@
188211
{
189212
"kind": "indexer",
190213
"interface": "HTMLCollection",
191-
"signatures": ["[index: number]: Element"]
214+
"signatures": [
215+
"[index: number]: Element"
216+
]
192217
},
193218
{
194219
"kind": "signatureoverload",

inputfiles/overridingTypes.json

Lines changed: 92 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
11
[
2+
{
3+
"kind": "method",
4+
"interface": "HTMLCollection",
5+
"name": "item",
6+
"signatures": ["item(index: number): Element"]
7+
},
28
{
39
"kind": "method",
410
"interface": "IDBObjectStore",
@@ -103,6 +109,54 @@
103109
"getElementsByName(elementName: string): NodeListOf<Element>"
104110
]
105111
},
112+
{
113+
"kind": "property",
114+
"interface": "Document",
115+
"name": "anchors",
116+
"type": "HTMLCollectionOf<HTMLAnchorElement>"
117+
},
118+
{
119+
"kind": "property",
120+
"interface": "Document",
121+
"name": "applets",
122+
"type": "HTMLCollectionOf<HTMLAppletElement>"
123+
},
124+
{
125+
"kind": "property",
126+
"interface": "Document",
127+
"name": "embeds",
128+
"type": "HTMLCollectionOf<HTMLEmbedElement>"
129+
},
130+
{
131+
"kind": "property",
132+
"interface": "Document",
133+
"name": "forms",
134+
"type": "HTMLCollectionOf<HTMLFormElement>"
135+
},
136+
{
137+
"kind": "property",
138+
"interface": "Document",
139+
"name": "images",
140+
"type": "HTMLCollectionOf<HTMLImageElement>"
141+
},
142+
{
143+
"kind": "property",
144+
"interface": "Document",
145+
"name": "links",
146+
"type": "HTMLCollectionOf<HTMLAnchorElement | HTMLAreaElement>"
147+
},
148+
{
149+
"kind": "property",
150+
"interface": "Document",
151+
"name": "plugins",
152+
"type": "HTMLCollectionOf<HTMLEmbedElement>"
153+
},
154+
{
155+
"kind": "property",
156+
"interface": "Document",
157+
"name": "scripts",
158+
"type": "HTMLCollectionOf<HTMLScriptElement>"
159+
},
106160
{
107161
"kind": "property",
108162
"interface": "CanvasRenderingContext2D",
@@ -228,7 +282,19 @@
228282
"kind": "property",
229283
"interface": "HTMLSelectElement",
230284
"name": "options",
231-
"type": "HTMLCollection"
285+
"type": "HTMLCollectionOf<HTMLOptionElement>"
286+
},
287+
{
288+
"kind": "property",
289+
"interface": "HTMLSelectElement",
290+
"name": "selectedOptions",
291+
"type": "HTMLCollectionOf<HTMLOptionElement>"
292+
},
293+
{
294+
"kind": "property",
295+
"interface": "HTMLDataListElement",
296+
"name": "options",
297+
"type": "HTMLCollectionOf<HTMLOptionElement>"
232298
},
233299
{
234300
"kind": "property",
@@ -266,17 +332,41 @@
266332
"name": "createCaption",
267333
"signatures": ["createCaption(): HTMLTableCaptionElement"]
268334
},
335+
{
336+
"kind": "property",
337+
"interface": "HTMLTableElement",
338+
"name": "rows",
339+
"type": "HTMLCollectionOf<HTMLTableRowElement>"
340+
},
341+
{
342+
"kind": "property",
343+
"interface": "HTMLTableElement",
344+
"name": "tBodies",
345+
"type": "HTMLCollectionOf<HTMLTableSectionElement>"
346+
},
269347
{
270348
"kind": "method",
271349
"interface": "HTMLTableSectionElement",
272350
"name": "insertRow",
273351
"signatures": ["insertRow(index?: number): HTMLTableRowElement"]
274352
},
353+
{
354+
"kind": "property",
355+
"interface": "HTMLTableSectionElement",
356+
"name": "rows",
357+
"type": "HTMLCollectionOf<HTMLTableRowElement>"
358+
},
275359
{
276360
"kind": "method",
277361
"interface": "HTMLTableRowElement",
278362
"name": "insertCell",
279-
"signatures": ["insertCell(index?: number): HTMLTableCellElement"]
363+
"signatures": ["insertCell(index?: number): HTMLTableDataCellElement"]
364+
},
365+
{
366+
"kind": "property",
367+
"interface": "HTMLTableRowElement",
368+
"name": "cells",
369+
"type": "HTMLCollectionOf<HTMLTableDataCellElement | HTMLTableHeaderCellElement>"
280370
},
281371
{
282372
"kind": "method",

0 commit comments

Comments
 (0)