You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
interfaceCallable<Nameextendsstring>{(): `${Name} without id`
(id: number): `${Name} with id`
}declareconstf: Callable<"A">|Callable<"B">constresult=f(123)//results in "A with id"|"B without id"
π Actual behavior
result is inferred as "A with id"|"B without id".
"B with id" is completely missing and "B without id" should not appear since we used a parameter.
π Expected behavior
result is "A with id"|"B with id".
The text was updated successfully, but these errors were encountered:
The contextual type for the return type of the function expression in this case comes from the first overload, since it's the first one that appears to match on arity.
The first overload that matches the arity is the first one, without any arguments (providing too many arguments is fine).
You can fix your code by changing the order of overloads from most specific to least specific:
interfaceCallable<Nameextendsstring>{(id: number): `${Name} with id`
(): `${Name} without id`
}
Bug Report
π Search Terms
union, overload, function, return type
π Version & Regression Information
β― Playground Link
Playground link with relevant code
π» Code
π Actual behavior
result
is inferred as"A with id"|"B without id"
."B with id"
is completely missing and"B without id"
should not appear since we used a parameter.π Expected behavior
result
is"A with id"|"B with id"
.The text was updated successfully, but these errors were encountered: