2
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?

4
  • 1
    Possible duplicate of Implementing TypeScript interface with bare function signature plus other fields Commented Dec 30, 2015 at 20:21
  • The solution doesn't work for me. Commented Dec 30, 2015 at 21:09
  • Why not what's wrong? Commented Dec 30, 2015 at 21:25
  • The variable needs a typedef. And so when I mention that it's of any particular type, either of type A or of type"any" I get errors Commented Dec 30, 2015 at 22:02

1 Answer 1

1

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

    }
}
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.