0

I get this compile error:

property 'prototype' does not exist on value of type 'Base'

on the following class, how can I get typescript to recognise the prototype object as a type of native Object from a constructor Function?

interface IBase {
  extend: any;
  prototype : any;
}

declare var Base : IBase;

class Base implements IBase {

  constructor() {}

  public extend( mixins : any ) : void {
    _.extend( this.prototype, mixins );
  }

}

1 Answer 1

3

this.prototype is probably not what you mean, since instances of Base don't have a prototype property (see yourself at runtime). Base, however, does:

interface IBase {
  extend: any;
}

class Base implements IBase {
  constructor() {}

  public extend( mixins : any ) : void {
    _.extend(Base.prototype, mixins );
  }
}

Of course, at this point, extend might as well be static, since it applies to all Base instances. Did you mean this instead?

  public extend( mixins : any ) : void {
    _.extend(this, mixins);
  }
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.