Implementation of interfaces typescript

69 Views Asked by At
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?

1

There are 1 best solutions below

0
Guillaume On

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() {

    }
}