-
-
Notifications
You must be signed in to change notification settings - Fork 361
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
[BUG] Can't use default function parameters in model.methods.set(name, function) #1602
Comments
See the documentation about this method and the examples model.methods.set(name, function)
So based on the current design, it doesn't seem to make sense to have a param with a default value since is always recommended to use the number of params when calling these methods. |
@ptejada, I believe the documentation text is not related to function default parameters, but rather to how the custom method handles the callback that is passed into it. It is clear that the current implementation in dynamoose does not support this functionality. However, I think it is essential to include this feature in custom methods. |
Are setters with default value params supported? No and you can find why in the documentation quoted. I am not saying I agree with how this is documented as a recommendation to always call these setters with the same number of arguments. Without following this recommendation the behavior of the handler will be unpredictable as you found out. Given the current implementation it sounds like it is a requirement to always call these helper methods with the same number of arguments. In other words, if you are always calling your helper method without params then the param with default is not even applicable. |
@ptejada, I completely agree. Either we need to update the documentation to provide more clarity, or we need to fix this behavior. |
Summary:
When using
model.methods.set(name, function)
to define a function, I have noticed that setting default parameters does not work as expected. Instead of the default values being applied, the function default values always returns undefined. However, the typeof operator identifies the type of the variable (default paramter) as a function. Additionally, when I apply .toString() to the function, it returns the representation of an arrow function.It seems that there is an issue with the way default parameters are handled when using model.methods.set(name, function). The default parameter values are not being assigned correctly, resulting in undefined being returned. Furthermore, the usage of .toString() on the function appears to generate the representation of an arrow function.
Code
Sandbox link
Current output and behavior:
Expected output and behavior:
Environment:
Operating System: Windows 10 Pro
Operating System Version: 22H2
Node.js version (
node -v
): 18.16.0NPM version: (
npm -v
): 9.5.1Dynamoose version: 3.1.0
The text was updated successfully, but these errors were encountered: