Overloaded function signature with a Promise will not provide .resolves().
See original GitHub issueUsing the Calculator example as a class, If i were to overload a method that is a promise with a void, it will not provide a resolve() method. ~~
class Calculator {
heavyOperation(): Promise<number> | void {
const a = 2;
}
}
~~
In the section for “Working with Promises” I can no longer do a .resolves()
const sub = Substitute.for<Calculator>();
sub.heavyOperation().resolves(); //<-- resolves does not exist
Error
Property ‘resolves’ does not exist on type ‘(void & { returns: (…args: (void | Promise<number>)[]) => void; throws: (exception: any) => never; } & { mimicks: (func: () => void | Promise<number>) => void; }) | (void & { …; } & { …; } & { …; }) | (Promise<…> & … 1 more … & { …; }) | (Promise<…> & … 2 more … & { …; })’.
Is there an alternative approach to accessing the .resolves()
or if this would be a feature request?
(Updated request)
Issue Analytics
- State:
- Created 3 years ago
- Comments:6
Top Results From Across the Web
Calling an overloaded function should resolve to best match ...
That overload would make calls that provide () => Promise<void> seem unsafe. Our workaround is to check all call signatures, which is imprecise ......
Read more >How to fix overloaded function with different signature
A possible solution or workaround might be to pull A::test into the scope of B , like struct B : A { using...
Read more >Jest and Typescript: Mocking Overload Signatures
Now we can provide any sort of mock implementation that adheres to our Promise-based signature, e.g. resolve different values for different ...
Read more >typescript method overloading in class
A class in terms of OOP is a blueprint for creating objects. The overload signatures need to fit into the implementation signature. Section...
Read more >Documentation - Advanced Types - TypeScript
When inferring from a type with multiple call signatures (such as the type of an overloaded function), inferences are made from the last...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@notanengineercom I’ll see if I can come up with a solution and submit a PR for it. For now, I created a facade for the piece in question and that keeps the caller unique. Aside from that, I’m very happy with the framework! 👍🏻👍🏻
Awesome, thanks for the support 😄