I'm using TypeScript on an Angular.js project and testing with Jasmine.
When I mock a method on an object using spyOn, Jasmine replaces the method with a function that has a calls property so you can do, for instance, thing.method.calls.count().
The problem is that the TypeScript compiler doesn't know about the calls property on the method and gives a compiler error:
property 'calls' does not exist on type '() => IPromise<IReport[]>'
How do I fix this error? Do I need to define a new interface that has a function signature as well as an object property? I've tried monkeying around with different interface configurations, but without luck so far.
How do I fix this error?
Basically add to the Function interface in a file like globals.d.ts. Demo:
interface Function {
calls: any;
}
var foo = ()=>null;
foo.calls; // okay
This trick is covered here : https://basarat.gitbooks.io/typescript/content/docs/types/lib.d.ts.html
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With