-
Notifications
You must be signed in to change notification settings - Fork 13k
Closed
Labels
CanonicalThis issue contains a lengthy and complete description of a particular problem, solution, or designThis issue contains a lengthy and complete description of a particular problem, solution, or designDeclinedThe issue was declined as something which matches the TypeScript visionThe issue was declined as something which matches the TypeScript visionRevisitAn issue worth coming back toAn issue worth coming back toSuggestionAn idea for TypeScriptAn idea for TypeScript
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!
thorn0
Metadata
Metadata
Assignees
Labels
CanonicalThis issue contains a lengthy and complete description of a particular problem, solution, or designThis issue contains a lengthy and complete description of a particular problem, solution, or designDeclinedThe issue was declined as something which matches the TypeScript visionThe issue was declined as something which matches the TypeScript visionRevisitAn issue worth coming back toAn issue worth coming back toSuggestionAn idea for TypeScriptAn idea for TypeScript