Amol Agrawal
Amol Agrawal

Reputation: 185

Implementation of interfaces typescript

interface A {
(obj? : any) : any;
func1() : void;
func2() :void;
} 

How do I write a class B that would implement A? How would I implement the parametrized constructor?

Upvotes: 2

Views: 70

Answers (1)

Guillaume
Guillaume

Reputation: 844

An interface cannot, by definition, contain a constructor. You have to move it in your implemented class :

interface A {
    func1(): void;
    func2(): void;
}

class B implements A {
    constructor(obj? : any) {

    }

    func1() {

    }

    func2() {

    }
}

Upvotes: 1

Related Questions