question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Overloaded function signature with a Promise will not provide .resolves().

See original GitHub issue

Using 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:closed
  • Created 3 years ago
  • Comments:6

github_iconTop GitHub Comments

1reaction
elAndyGcommented, May 5, 2020

@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! 👍🏻👍🏻

0reactions
notanengineercomcommented, May 5, 2020

Awesome, thanks for the support 😄

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found