Reputation: 860
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;
};
Upvotes: 3
Views: 1334
Reputation: 1206
You need to use interface to extend the Element first.
interface Element{
astyle(props:string[]);
}
Upvotes: 1