I'm trying to add TypeScript typings to a 3rd party JavaScript library. Most of the class methods take another instance of the same class and return a new instance, but they'll also accept the same overloaded constructor arguments in place of an actual instance of the class. I'm trying to avoid writing the same overloaded signature for each of the class's many methods but I'm not sure how exactly to do this in my .d.ts file.
For example, I could write out each one like...
class Foo {
constructor(x: number);
constructor(x: number, y: number);
constructor({ x: number, y: number });
Fizz(foo: Foo): Foo;
Fizz(x: number): Foo;
Fizz(x: number, y: number): Foo;
Fizz({ x: number, y: number }): Foo;
Buzz(foo: Foo): Foo;
Buzz(x: number): Foo;
Buzz(x: number, y: number): Foo;
Buzz({ x: number, y: number }): Foo;
// etc... for several methods
}
But it'd be preferable to do something like...
class Foo {
constructor(x: number);
constructor(x: number, y: number);
constructor({ x: number, y: number });
// I'd like some sort of syntax like...
Fizz(constructor()): Foo;
Buzz(constructor()): Foo;
}
Can I easily declare and reuse an overloaded method signature?