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
{{ message }}
Repository navigation
.toBeCallableWith() does not work with generic functions or overloadsΒ #50
expectTypeOf(foo).toBeCallableWith("abc","efg");~~~~~Argumentoftype'string'isnotassignabletoparameteroftype'number'.expectTypeOf(foo).toBeCallableWith(123,456);foo("abc","efg");// but all is good herefoo(123,456);
Hm.. If a simple foo() does the job (and does it better!), what is the purpose of .toBeCallableWith()? I mean, .toEqualTypeOf() works perfectly in both of the cases I mentioned above:
.not.toBeCallableWith() could handle a check which .toEqualTypeOf() cannot and would be more useful than // @ts-expect-error. Unfortunately it is not implemented at the moment.
Hm.. If a simple foo() does the job (and does it better!), what is the purpose of .toBeCallableWith()? I mean, .toEqualTypeOf() works perfectly in both of the cases I mentioned above:
Yeah, I sometimes regret adding toBeCallableWith for this reason. The advantages of it:
It's more explicit - it says "I am testing that this function accepts these parameters" rather than expectTypeOf(foo(...)).toEqualTypeOf<...>() which looks more like "I am testing that this function has this return type".
It doesn't involve actually calling the function, which may have side-effects.
But outside of those, you're probably better off with foo(...) in this case.
Iβm leaving the issue open in case you would like to document the limitation with overloaded and generic functions. Feel free to close, if that does not look significant.
Activity
mmkal commentedon Jan 17, 2024
Yeah, I sometimes regret adding
toBeCallableWithfor this reason. The advantages of it:expectTypeOf(foo(...)).toEqualTypeOf<...>()which looks more like "I am testing that this function has this return type".But outside of those, you're probably better off with
foo(...)in this case.mrazauskas commentedon Jan 17, 2024
Thanks for explanation.
Iβm leaving the issue open in case you would like to document the limitation with overloaded and generic functions. Feel free to close, if that does not look significant.
Add limitations section