I would like to extend the built-in class HTMLElement with additional methods. Maybe I'm going mad, but I thought the following was the official idiom:
interface HTMLElement {
swapChildBefore(remove: HTMLElement, insert: HTMLElement, before: HTMLElement): void;
}
HTMLElement.prototype.swapChildBefore =
function (remove: HTMLElement, insert: HTMLElement, before: HTMLElement): void {
this.removeChild(remove)
this.insertBefore(insert, before)
}
At least, according to How does prototype extend on typescript?, something like this should work.
However, this seems to hide all the existing methods on HTMLElement. Is that because I've declared an interface, which hides the class of the same name? But this idiom seems to work fine with Object and Array, which are also classes.
HTMLElementalready has aswapChildBeforemethod taking twoHTMLElementas parameters. You should use a different name for the method if you want a variation with three parameters.