0

here is an example of my class with the methods in question

class Example {
    constructor(info) {
        // call validateInfo(info)
    }

    static validateInfo(info):void {
        // validate the info
    }

I would like to call validateInfo in the constructor, but I can't just do this with this.validateInfo(info) because it is a static method.

In Javascript, I could do this:

    constructor(info) {
        this.constructor.validateInfo(info)
    }

but, in Typescript this gives the following error:

error TS2339: Property 'validateInfo' does not exist on type 'Function'.

I understand the error message, but is there a Typescript equivalent for the Javascript solution?

0

1 Answer 1

1

The problem is that a subclass may have called the constructor, not Example. I'd reference Example specifically:

constructor(info) {
    Example.validateInfo(info)
}

Another option to consider would be making it a normal method rather than a static method.

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

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.