You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Cloud functions and Typescript No argument for validationHandler in beforeSave trigger #7016
I'm using Parse Server 4.4.0 and @types/parse 2.12.7 with TypeScript.
All is working as expected, thanks for your work :)
But, I'm trying to add a validation handler on a before save trigger, as described on the documentaion : Parse.Cloud.beforeSave("Review", (request) => { // do any additional beforeSave logic here },{ fields: { stars : { required:true, options: stars => { return stars >= 1 && stars =< 5; }, error: 'Your review must be between one and five stars' } } });
But, in the index.d.ts used by Typescript, here is the declaration : function beforeSave(arg1: any, func?: (request: BeforeSaveRequest) => Promise<void> | void): void;
And here is the JS code from your GitHub sources : ParseCloud.beforeSave = function (parseClass, handler, validationHandler) {
As you can see, the "validationHandler" arguments for the method ParseCloud.beforeSave is missing in the declaration of the index.d.ts file. So, in Typescript, I can't add field validation like it's done in the documentation.
Am I missing somthing or is it really an issue ?
Thanks for help.
Steps to reproduce
Just install parse-server and @types/parse and use it with typescript.
Actual Outcome
In the index.d.ts : function beforeSave(arg1: any, func?: (request: BeforeSaveRequest) => Promise<void> | void): void;
Expected Outcome
In the index.d.ts : function beforeSave(arg1: any, func?: (request: BeforeSaveRequest) => Promise<void> | void, func?: (any) => Promise<void> | void): void;
Thanks for reporting. To report an issue, please use the issue template provided when you create an issue. The template asks for essential information which helps us to investigate the issue.
(Parse.Cloud as any).beforeSave("Review",
(request) => { // do any additional beforeSave logic here }, {
fields: {
stars : {
required:true, options: stars => { return stars >= 1 && stars =< 5; },
error: 'Your review must be between one and five stars'
}
}
});
should do it. It's hacky, but works till the definition is up to date.
The problem is clearly an outdated definition file in the DefinitelyTyped Repository. I think this issue can be closed here. Maybe, at some point in the future, the definitions should be maintained here.
Activity
mtrezza commentedon Nov 18, 2020
Thanks for reporting. To report an issue, please use the issue template provided when you create an issue. The template asks for essential information which helps us to investigate the issue.
alljinx commentedon Nov 18, 2020
Sorry, updated !
dblythy commentedon Nov 19, 2020
I can confidently say I have no idea how typescript works, but it seems as the issue is here, in the typescript library.
I might be wrong, but I don't know if this is an issue with Parse Server, or if the typescript definitions need to be updated in that repo.
dblythy commentedon Nov 19, 2020
See this discussion
alljinx commentedon Nov 19, 2020
OK so I will wait for the merge...
Thx !
dblythy commentedon Nov 19, 2020
I would imagine the fastest way of getting this feature on Typescript would be to submit a PR to the typescript library.
fastrde commentedon Nov 20, 2020
Quicktip:
should do it. It's hacky, but works till the definition is up to date.
alljinx commentedon Nov 20, 2020
Thank you fastrde, that's exactly what I did :D
fastrde commentedon Nov 23, 2020
The problem is clearly an outdated definition file in the DefinitelyTyped Repository. I think this issue can be closed here. Maybe, at some point in the future, the definitions should be maintained here.
mtrezza commentedon Nov 23, 2020
I'm closing this as it does not seem to be a Parse Server issue.
The solution seems to be to raise this issue in a 3rd part library.
Feel free to comment if you have any questions and we can re-open this issue.