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
This is the behavior in every version I tried, and I reviewed the FAQ for entries about the problem regarding ambiguously calling a function with overloads.
What happens basically is that TypeScript expects one of the two overload signatures to be used while I guess technically it uses both signatures. It just so happens that it comes down to actually trying to call the function by it's implementation arguments which I am aware are not the signatures of the function itself (which would be the overloaded signatures without body) but I do feel that this is flawed. The reason I feel like this is flawed is because of the example that does work. Which is destructing the args parameter of the bar function to the first argument and the rest arguments that follow, to then check whether the first argument is a boolean or not. If it is a boolean, it calls the function foo the exact same way as it would call the function foo if it weren't a boolean. The last example is to call the function foo with only the arguments as rest parameter which doesn't work either but is actually no different from the first example with destructing.
🙂 Expected behavior
I would expect all three examples to be valid, not because it matches the implementation arguments of the foo function, but because it ambiguously matches two of the overload signatures of the foo function at the same time.
🔎 Search Terms
ambiguous, overload, rest, spread, destructing
🕗 Version & Regression Information
⏯ Playground Link
https://www.typescriptlang.org/play?#code/GYVwdgxgLglg9mABMOcAUBDATgcwIwBciAzlFjGDogD6JggC2ARgKZYA0iAdD9jsUSaoANiwxgA2gF0AlEQBucGABMA3AChQkWAmSo0PLnwGIhcUeOlzEilRq3R4SFOkPGiEkmQpVa9Zmw0piJiYJyGZhaSUpyyiADe6oiIAPQpiAAicCRwDCxQABY+6gC+6prgjrpM2Aa8uCaepOSUQf6sWEGRoeE83ZYxiHGJyRAIpIiewDBYpACCuL1cWCzzDUOIALyIxhrJaZlwq2AA5FCIAO5wWADWSXro07NQCzhLK2v8Mnup6Vmrl2ud2SMGAiDQUAAngAHFhwMFPT5bTbbE79U4yBL3ZIuNCIl6Lbg8D4Er4-EqIFjCYgsLHJHH6fGvd6rUnEb73Mr7P5HYinc5XW73XFuBockpAA
💻 Code
Workbench Repro
🙁 Actual behavior
What happens basically is that TypeScript expects one of the two overload signatures to be used while I guess technically it uses both signatures. It just so happens that it comes down to actually trying to call the function by it's implementation arguments which I am aware are not the signatures of the function itself (which would be the overloaded signatures without body) but I do feel that this is flawed. The reason I feel like this is flawed is because of the example that does work. Which is destructing the args parameter of the
bar
function to the first argument and the rest arguments that follow, to then check whether the first argument is a boolean or not. If it is a boolean, it calls the functionfoo
the exact same way as it would call the functionfoo
if it weren't a boolean. The last example is to call the functionfoo
with only the arguments as rest parameter which doesn't work either but is actually no different from the first example with destructing.🙂 Expected behavior
I would expect all three examples to be valid, not because it matches the implementation arguments of the
foo
function, but because it ambiguously matches two of the overload signatures of thefoo
function at the same time.Additional information about the issue
Duplicate of #14107
The text was updated successfully, but these errors were encountered: