Here is an example of a factory function created in ES5:
function MyClass(val) {
if (!(this instanceof MyClass)) {
return new MyClass(val);
}
this.val = val;
}
You can call this function with or without the new
keyword:
var a = new MyClass(5);
var b = MyClass(5);
While this code works well in Typescript, I am struggling to create a declares file that describes the merging behavior for both cases. Is there a solution to achieve this?