How can I write typescript conforming to the following javascript?

var _ =require('lodash');
var Controller=function(){};
 Controller.prototype.index=function(req,res){
   res.ok();
 };
 Controller.extend=function(object){
      return _.extend({},Controller.prototype,object);
 };

      

I tried the following typescript but it adds the extension as Controller.prototype.extend instead of Controller.extend ()

var _ = require('lodash');
class Controller
{
    index(){
        console.log("hi");
    }
    extends(object) {

    return _.extend({}, Controller.prototype, object);
    }
}

      

how can i change my typescript to get the above javascript?

+3


source to share


1 answer


You define an instance method that is part of the object's prototype where you should use a static method (part of the class).

All you need to change is the to declaration extends(object)

:



static extends(object) {
  ...
}

      

+3


source







All Articles