Maybe your example is simplified, and you are trying to achieve something more complex under the hood, but If i understand your code correctly you just want to return an instance of the Register function without the New operator.
The only option i can think of is to trick the TS compiler, and to specify the return type as void, and then in your variables use type any.
module Register {
export function Register(x: string): void {
if (!(this instanceof Register)) {
return new Register(x);
}
this.value = x;
}
export interface Instance {
new (x: string): Instance;
value: string;
}
}
export = Register;
var rega: any = Register.Register("something");
console.log(rega.value); // something
Update: Since you have a problem with specifying any
as the explicit type for each variable, then you could use Object.create() instead of the new operator:
module Register {
export function Register(x: string): Instance {
var r = Object.create(Register);
r.value = x;
return r;
}
export interface Instance {
new (x: string): Instance;
value: string;
}
}
export = Register;
var rega = Register.Register("something");
console.log(rega.value); // something