1

Given the following interface

interface Expando { new<T extends {}>(template: T): T & Expando; } 

I tried to implement this like so

class Expando implements ExpandoConstructor { constructor(template: {}) { } } 

But I get an error because the constructor definition is incomplete. How do I implement this interface?

1 Answer 1

1

You can't have a class implement a constructor interface because this interface describes static properties of the class.

You can do this:

interface ExpandoConstructor { new<T extends {}>(template: T): T & Expando; } class Expando { constructor(template: {}) {} } let ctor = Expando as ExpandoConstructor; let instance = new ctor({}); 

(code in playground)

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.