sinonjs / sinon

Test spies, stubs and mocks for JavaScript.
https://sinonjs.org/
Other
9.63k stars 770 forks source link

SinonStub typings after withArgs is incorrect #2442

Closed jmclean-starburst closed 2 years ago

jmclean-starburst commented 2 years ago

Describe the bug When calling sinon.stub(someClass, "someProperty").withArgs("someArg"), the return type has attributes parent and matchingArguments. Intellisense is yelling when you try to access the .parent attribute bc it is not within type SinonStub

this means I am unable to call myStub.parent.callCount unless i decorate the line with // @ts-ignore

In fact, myStub.called will yield false, however myStub.withArgs("someArg").called will yield true.

Expected behavior Intellisense will correctly handle a SinonStub after it is initialized w/ withArgs

Context (please complete the following information):

Additional context Add any other context about the problem here.

fatso83 commented 2 years ago

There is a reason we ask for some way of reproducing the issue:

~/code/sinon (master)
$ grep SinonStub | wc -l
0

As you can see, we do not provide anything called SinonStub. Given the @ts-ignore, it seems this is Typescript related, and we do not provide TypeScript definitions (that was only a short-lived experiment in v7 that did not turn out well), only JSDoc which, although works, is inferior in what it could provide compared to TypeScript. You probably want to file a bug (or better, a Pull Request :angel: that scratches your itch) to the Definitely Typed project, as we do not provide any support for these externally maintained types.

It's relatively painless to get a fix in: the PRs I have submitted related to Sinon usually got reviewed and approved within 4-5 days.