Closed
Description
I was just working with Big.js and tried to pass a union type into its constructor function. It seems that union types don't play nice with old-style overloaded constructors. Please consider the code below that errors with TypeScript 1.4. I would have expected this to work.
interface BigJS_Constructors {
new (value: number): BigJS;
new (value: string): BigJS;
new (value: BigJS): BigJS;
}
interface BigJS extends BigJS_Constructors {
abs(): BigJS;
/* more... */
}
var Big : BigJS;
class MyThing {
public value : BigJS;
constructor(value: number | string | BigJS) {
this.value = new Big(value); //This is an error in 1.4.
}
}
If I change the new
signature under BigJS_Constructors
to new (value: number | string | BigJS) : BigJS;
, and eliminate the other two options, it works fine, but to me the two styles should be identical in this case.
My apologies if I'm doing something stupid here. Thanks!