Michael Yuan Michael Yuan - 1 year ago 178
HTML Question

Extend Element prototype using TypeScript

Given the javascript like below, is there a corresponding TypeScript to do the same thing?

I just need to extend the html dom element prototype but cannot figure out a correct TypeScript to do this without compile errors.

Element.prototype.astyle = function actualStyle(props) {
var el = this;
var compStyle = window.getComputedStyle(el, null);
for (var i = 0; i < props.length; i++) {
var style = compStyle[props[i]];
if (style != null) {
return style;
return null;

Answer Source

You need to use interface to extend the Element first.

interface Element{
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download