Here is the code that I wrote:
var checkboxes = this.element.querySelectorAll("input[type=checkbox]") as NodeListOf<HTMLInputElement>;
checkboxes.forEach(ele => {
var key = ele.name;
if (data.hasOwnProperty(key)) {
if (!this.isArray(data[key])) {
var temp = data[key];
data[key] = [temp];
}
} else {
data[key] = [];
}
});
Unfortunately, an error occurred:
Error TS2339: Property 'forEach' does not exist on type 'NodeListOf'.
interface NodeListOf<TNode extends Node> extends NodeList {
length: number;
item(index: number): TNode;
[index: number]: TNode;
}
interface NodeList {
entries(): IterableIterator<[number, Node]>;
forEach(callbackfn: (value: Node, index: number, listObj: NodeList) => void, thisArg?: any): void;
keys(): IterableIterator<number>;
values(): IterableIterator<Node>;
[Symbol.iterator](): IterableIterator<Node>;
}
I am puzzled as to why the 'forEach' method is missing in the 'NodeListOf' interface, since it inherits from 'NodeList' which does have the 'forEach' method. Can anyone shed some light on this issue?