Two interfaces with (at the same signatures) overloaded functions as members, combined into an union type, loose the overload information.
TypeScript Version: 3.9.0-dev.20200328
Search Terms:
Union Overload resolve interface
Code
type Wrap<T> = {wrap: T}
type A<Values extends any[]> = {
get(): Values
get(overload: string): Wrap<Values>
}
type B<Value> = {
get(): Value
get(overload: string): Wrap<Value>
}
type AB<Values extends any[]> = A<Values> | B<Values[number]>
let ab: AB<(string | number)[]>
let res = ab.get("overload") // typeof (string | number | Wrap<(string | number)[]>)
res should be only typeof (Wrap<string | number> | Wrap<(string | number)[]>) since both subtypes (A and B) of the union type (AB) have the same overload signatures
Expected behavior:
res in the above code should be the same as A and B seperatly executed.
type AB1<Values extends any[]> = A<Values>
let ab1: AB1<(string | number)[]>
let res1 = ab1.get("overload")
type AB2<Values extends any[]> = B<Values[number]>
let ab2: AB2<(string | number)[]>
let res2 = ab2.get("overload")
let whatResShouldBe: (typeof res1) | (typeof res2)
Actual behavior:
res in the first example is typeof (string | number | Wrap<(string | number)[]>) and not as the union suggests (typeof res1) | (typeof res2) or (Wrap<string | number> | Wrap<(string | number)[]>)
Playground Link
Two interfaces with (at the same signatures) overloaded functions as members, combined into an union type, loose the overload information.
TypeScript Version: 3.9.0-dev.20200328
Search Terms:
Union Overload resolve interface
Code
resshould be onlytypeof (Wrap<string | number> | Wrap<(string | number)[]>)since both subtypes (AandB) of the union type (AB) have the same overload signaturesExpected behavior:
resin the above code should be the same asAandBseperatly executed.Actual behavior:
resin the first example istypeof (string | number | Wrap<(string | number)[]>)and not as the union suggests(typeof res1) | (typeof res2)or(Wrap<string | number> | Wrap<(string | number)[]>)Playground Link