Skip to content

Commit 0ab39ea

Browse files
committed
Iterable DOM collections types
1 parent bef5ff5 commit 0ab39ea

File tree

7 files changed

+314
-0
lines changed

7 files changed

+314
-0
lines changed
Lines changed: 271 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,271 @@
1+
// use only with DOM lib
2+
interface ArrayIterator<T> extends IteratorObject<T, BuiltinIteratorReturn, unknown> { // @type-options no-export
3+
[Symbol.iterator](): ArrayIterator<T>;
4+
}
5+
6+
interface DOMTokenList { // @type-options no-export
7+
/**
8+
* Calls a defined callback function on each element of the DOMTokenList,
9+
* passing the element, its index, and the entire DOMTokenList as arguments.
10+
* @param callbackfn
11+
* @param thisArg
12+
*/
13+
forEach(
14+
callbackfn: (value: Element, index: number, collection: DOMTokenList) => void,
15+
thisArg?: any
16+
): void;
17+
18+
/**
19+
* Returns an iterable of keys in the DOMTokenList.
20+
*/
21+
keys(): Iterable<number>;
22+
23+
/**
24+
* Returns an iterable of values in the DOMTokenList.
25+
*/
26+
values(): Iterable<Element>;
27+
28+
/**
29+
* Returns an iterable of key, value pairs in the DOMTokenList.
30+
*/
31+
entries(): Iterable<[number, Element]>;
32+
33+
[Symbol.iterator](): Iterable<Element>;
34+
}
35+
36+
interface NodeList { // @type-options no-export
37+
/**
38+
* Calls a defined callback function on each element of the NodeList,
39+
* passing the element, its index, and the entire NodeList as arguments.
40+
* @param callbackfn
41+
* @param thisArg
42+
*/
43+
forEach(
44+
callbackfn: (value: Node, index: number, collection: NodeList) => void,
45+
thisArg?: any
46+
): void;
47+
48+
/**
49+
* Returns an iterable of keys in the NodeList.
50+
*/
51+
keys(): Iterable<number>;
52+
53+
/**
54+
* Returns an iterable of values in the NodeList.
55+
*/
56+
values(): Iterable<Node>;
57+
58+
/**
59+
* Returns an iterable of key, value pairs in the NodeList.
60+
*/
61+
entries(): Iterable<[number, Node]>;
62+
63+
/**
64+
* Returns an iterable of values in the NodeList.
65+
*/
66+
[Symbol.iterator](): Iterable<Node>;
67+
}
68+
69+
interface CSSRuleList { // @type-options no-export
70+
/**
71+
* Returns an iterable of values in the CSSRuleList.
72+
*/
73+
[Symbol.iterator](): Iterable<CSSRuleList>;
74+
}
75+
76+
interface CSSStyleDeclaration { // @type-options no-export
77+
/**
78+
* Returns an iterable of values in the CSSStyleDeclaration.
79+
*/
80+
[Symbol.iterator](): Iterable<CSSStyleDeclaration>;
81+
}
82+
83+
interface CSSValueList { // @type-options no-export
84+
/**
85+
* Returns an iterable of values in the CSSValueList.
86+
*/
87+
[Symbol.iterator](): Iterable<CSSValueList>;
88+
}
89+
90+
interface ClientRectList { // @type-options no-export
91+
/**
92+
* Returns an iterable of values in the ClientRectList.
93+
*/
94+
[Symbol.iterator](): Iterable<ClientRectList>;
95+
}
96+
97+
interface DOMRectList { // @type-options no-export
98+
/**
99+
* Returns an iterable of values in the DOMRectList.
100+
*/
101+
[Symbol.iterator](): Iterable<DOMRectList>;
102+
}
103+
104+
interface DOMStringList { // @type-options no-export
105+
/**
106+
* Returns an iterable of values in the DOMStringList.
107+
*/
108+
[Symbol.iterator](): Iterable<DOMStringList>;
109+
}
110+
111+
interface DataTransferItemList { // @type-options no-export
112+
/**
113+
* Returns an iterable of values in the DataTransferItemList.
114+
*/
115+
[Symbol.iterator](): Iterable<DataTransferItemList>;
116+
}
117+
118+
interface FileList { // @type-options no-export
119+
/**
120+
* Returns an iterable of values in the FileList.
121+
*/
122+
[Symbol.iterator](): Iterable<FileList>;
123+
}
124+
125+
interface HTMLAllCollection { // @type-options no-export
126+
/**
127+
* Returns an iterable of values in the HTMLAllCollection.
128+
*/
129+
[Symbol.iterator](): Iterable<HTMLAllCollection>;
130+
}
131+
132+
interface HTMLCollection { // @type-options no-export
133+
/**
134+
* Returns an iterable of values in the HTMLCollection.
135+
*/
136+
[Symbol.iterator](): ArrayIterator<Element>;
137+
}
138+
139+
interface HTMLFormElement { // @type-options no-export
140+
/**
141+
* Returns an iterable of values in the HTMLFormElement.
142+
*/
143+
[Symbol.iterator](): Iterable<Element>;
144+
}
145+
146+
interface HTMLSelectElement { // @type-options no-export
147+
/**
148+
* Returns an iterable of values in the HTMLSelectElement.
149+
*/
150+
[Symbol.iterator](): Iterable<HTMLOptionElement>;
151+
}
152+
153+
interface MediaList { // @type-options no-export
154+
/**
155+
* Returns an iterable of values in the MediaList.
156+
*/
157+
[Symbol.iterator](): Iterable<MediaList>;
158+
}
159+
160+
interface MimeTypeArray { // @type-options no-export
161+
/**
162+
* Returns an iterable of values in the MimeTypeArray.
163+
*/
164+
[Symbol.iterator](): Iterable<MimeTypeArray>;
165+
}
166+
167+
interface NamedNodeMap { // @type-options no-export
168+
/**
169+
* Returns an iterable of values in the NamedNodeMap.
170+
*/
171+
[Symbol.iterator](): Iterable<NamedNodeMap>;
172+
}
173+
174+
interface PaintRequestList { // @type-options no-export
175+
/**
176+
* Returns an iterable of values in the PaintRequestList.
177+
*/
178+
[Symbol.iterator](): Iterable<PaintRequestList>;
179+
}
180+
181+
interface Plugin { // @type-options no-export
182+
/**
183+
* Returns an iterable of values in the Plugin.
184+
*/
185+
[Symbol.iterator](): Iterable<Plugin>;
186+
}
187+
188+
interface PluginArray { // @type-options no-export
189+
/**
190+
* Returns an iterable of values in the PluginArray.
191+
*/
192+
[Symbol.iterator](): Iterable<PluginArray>;
193+
}
194+
195+
interface SVGLengthList { // @type-options no-export
196+
/**
197+
* Returns an iterable of values in the SVGLengthList.
198+
*/
199+
[Symbol.iterator](): Iterable<SVGLengthList>;
200+
}
201+
202+
interface SVGNumberList { // @type-options no-export
203+
/**
204+
* Returns an iterable of values in the SVGNumberList.
205+
*/
206+
[Symbol.iterator](): Iterable<SVGNumberList>;
207+
}
208+
209+
interface SVGPathSegList { // @type-options no-export
210+
/**
211+
* Returns an iterable of values in the SVGPathSegList.
212+
*/
213+
[Symbol.iterator](): Iterable<SVGPathSegList>;
214+
}
215+
216+
interface SVGPointList { // @type-options no-export
217+
/**
218+
* Returns an iterable of values in the SVGPointList.
219+
*/
220+
[Symbol.iterator](): Iterable<SVGPointList>;
221+
}
222+
223+
interface SVGStringList { // @type-options no-export
224+
/**
225+
* Returns an iterable of values in the SVGStringList.
226+
*/
227+
[Symbol.iterator](): Iterable<SVGStringList>;
228+
}
229+
230+
interface SVGTransformList { // @type-options no-export
231+
/**
232+
* Returns an iterable of values in the SVGTransformList.
233+
*/
234+
[Symbol.iterator](): Iterable<SVGTransformList>;
235+
}
236+
237+
interface SourceBufferList { // @type-options no-export
238+
/**
239+
* Returns an iterable of values in the SourceBufferList.
240+
*/
241+
[Symbol.iterator](): Iterable<SourceBufferList>;
242+
}
243+
244+
interface StyleSheetList { // @type-options no-export
245+
/**
246+
* Returns an iterable of values in the StyleSheetList.
247+
*
248+
*/
249+
[Symbol.iterator](): Iterable<SourceBufferList>;
250+
}
251+
252+
interface TextTrackCueList { // @type-options no-export
253+
/**
254+
* Returns an iterable of values in the TextTrackCueList.
255+
*/
256+
[Symbol.iterator](): Iterable<TextTrackCueList>;
257+
}
258+
259+
interface TextTrackList { // @type-options no-export
260+
/**
261+
* Returns an iterable of values in the TextTrackList.
262+
*/
263+
[Symbol.iterator](): Iterable<TextTrackList>;
264+
}
265+
266+
interface TouchList { // @type-options no-export
267+
/**
268+
* Returns an iterable of values in the TouchList.
269+
*/
270+
[Symbol.iterator](): Iterable<TouchList>;
271+
}

packages/core-js/modules/web.dom-collections.entries.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// types: web/iterable-dom-collections
12
'use strict';
23
var domIterablesDefineMethod = require('../internals/dom-iterables-define-method');
34

packages/core-js/modules/web.dom-collections.for-each.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// types: web/iterable-dom-collections
12
'use strict';
23
var domIterablesDefineMethod = require('../internals/dom-iterables-define-method');
34

packages/core-js/modules/web.dom-collections.iterator.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// types: web/iterable-dom-collections
12
'use strict';
23
var domIterablesDefineMethod = require('../internals/dom-iterables-define-method');
34
var wellKnownSymbol = require('../internals/well-known-symbol');

packages/core-js/modules/web.dom-collections.keys.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// types: web/iterable-dom-collections
12
'use strict';
23
var domIterablesDefineMethod = require('../internals/dom-iterables-define-method');
34

packages/core-js/modules/web.dom-collections.values.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// types: web/iterable-dom-collections
12
'use strict';
23
var domIterablesDefineMethod = require('../internals/dom-iterables-define-method');
34
var wellKnownSymbol = require('../internals/well-known-symbol');
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import 'core-js/full';
2+
3+
declare const nodeList: NodeList
4+
nodeList.forEach((value: Node, key: number, list: NodeList): void => {});
5+
nodeList.forEach((value: Node, key: number, list: NodeList): void => {}, []);
6+
// @ts-expect-error
7+
nodeList.forEach();
8+
9+
const k1: Iterable<number> = nodeList.keys();
10+
// @ts-expect-error
11+
nodeList.keys('string');
12+
13+
const v: Iterable<Node> = nodeList.values();
14+
// @ts-expect-error
15+
nodeList.values('string');
16+
17+
const e: Iterable<[number, Node]> = nodeList.entries();
18+
// @ts-expect-error
19+
nodeList.entries('string');
20+
21+
declare const domTokenList: DOMTokenList
22+
23+
domTokenList.forEach((value: Node, key: number, list: DOMTokenList): void => {});
24+
domTokenList.forEach((value: Node, key: number, list: DOMTokenList): void => {}, []);
25+
// @ts-expect-error
26+
domTokenList.forEach();
27+
28+
const fomKeys: Iterable<number> = domTokenList.keys();
29+
// @ts-expect-error
30+
domTokenList.keys('string');
31+
32+
const domValues: Iterable<Element> = domTokenList.values();
33+
// @ts-expect-error
34+
domTokenList.values('string');
35+
36+
const domEntries: Iterable<[number, Element]> = domTokenList.entries();
37+
// @ts-expect-error
38+
domTokenList.entries('string');

0 commit comments

Comments
 (0)