-
-
Notifications
You must be signed in to change notification settings - Fork 16
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
support interfaces with call signatures #81
Comments
Hi Joshua, thank you for spending time using the library and improving it. You are right, the library doesnt currently support interface call signature, however extending it to fully support it will require a bit more work because an interface can also have properties. Let's say we have an interface interface InterfaceWithCallSignature {
(a: number): number;
(a: string): string;
b: string;
} There are few requirements.
It's all possible but I would concentrate on point 1 and 3. const interfaceWithCallSignature: InterfaceWithCallSignature = Object.assign(function(a: number | string): any {
if (typeof a === 'string') {
return a;
} else {
return a;
}
}, {
b: '',
}); To reach this point we have to change the way the library generate the output. I will work on a POC this evening. If you want to investigate where the exported object is generated in ts-auto-mock you can look into mockCall.ts link thats where its receiveing the properties. |
@joshuavial I've created a PR that will solve this issue. |
I've just published a new version -> 1.2.1 that will cover this scenario. I'll leave the issue open until you've tested it :) |
Yep, works perfectly. Thanks! |
Great library - I've been trying to extend it to support call signatures in an interface but am getting a little lost.
This is the code that I'd like to work
I've played around with using
typeChecker.getSignaturesOfType
to get hold of the call signature but am struggling to find the right way to return a function.joshuavial@21dbe1d has an example of what I've been trying - any tips on the best way to solve this?
The text was updated successfully, but these errors were encountered: