1

I have code which uses function overload, something like:

function f0(v: Object): void { }

function f1(a: number, b: number): void;
function f1(a: string, b: string): void;
function f1(a: any, b: any): void {
    f0(a); // OK
}

That I would like to convert using union types, but I get an error:

function f1<T extends number | string>(a: T, b: T): void {
    f0(a); // Error: Argument of type 'T' is not assignable to parameter of type 'Object'.
}

What's wrong here, knowing that the following is OK:

function f2(v: number | string) {
    f0(v);
}
function f3<T extends number>(v: T) {
    f0(v);
}
function f4<T extends string>(v: T) {
    f0(v);
}
stephanedr
  • 21
  • 4

1 Answers1

1

I finally asked to MS and it seems to be a bug: https://github.com/Microsoft/TypeScript/issues/2576

stephanedr
  • 21
  • 4