0

I have tried to add a declaration file and a few other things but nothing is working so far:

I basically want to set visible to be a function on the HTML Element object. This is what I have and the linter has visible underlined saying Property 'visible' does not exist on type 'Element'. What am I doing wrong?

Element.prototype.visible = function() {
  return (!window.getComputedStyle(this)
    || window.getComputedStyle(this).getPropertyValue('display') == ''
    || window.getComputedStyle(this).getPropertyValue('display') != 'none')
}

I'm using Typescript 3.8

1 Answer 1

1

You need to augment global declarations:

export {};

declare global {
    interface Element {
        visible: () => boolean;
    }
}

Element.prototype.visible = function() {
    return (!window.getComputedStyle(this)
        || window.getComputedStyle(this).getPropertyValue('display') == ''
        || window.getComputedStyle(this).getPropertyValue('display') != 'none')
};

export {}; is used to make this file a module. If you already have any other exports or imports - you don't need this

Sign up to request clarification or add additional context in comments.

Comments

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.