3

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;
};
0

1 Answer 1

1

You need to use interface to extend the Element first.

interface Element{
    astyle(props:string[]);
}
Sign up to request clarification or add additional context in comments.

1 Comment

Make sure to put this in a .d.ts file located in the same folder as your tsconfig.json

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.