AUR0506
Error Message
AUR0506: Invalid callback for @watch decorator: <callback>
Where <callback> represents the value that was provided as the callback but is not a function.
Description
This error occurs when using the @watch decorator in a view model, but the provided callback (the function that should execute when the watched property changes) is not actually a function type at runtime. The @watch decorator requires a valid function to call when changes are detected.
Cause
Incorrect Callback Type: The most common cause is providing a value that is not a function as the callback argument to
@watch. This could be a typo in a function name (string), a property that isn't a function,null,undefined, etc.Callback Not Defined: The function specified as the callback might not be defined on the view model class, or it might be misspelled.
Conditional Assignment: The property intended to hold the callback function might be conditionally assigned, and
@watchis evaluated when the property holds a non-function value.
The @watch decorator can be used in several ways:
@watch(expression): Decorating a method directly. The method itself is the callback.@watch(expression, callbackFn): Decorating the class.callbackFnmust be a function.@watch(callbackFn): Decorating the class. Watches the class instance,callbackFnmust be a function.@watch(objectProperty): Decorating a callback method.objectPropertyexpression is watched.
This error typically relates to the forms where an explicit callback function is provided or expected.
Solution
Verify Callback is a Function: Ensure that the value passed as the callback to
@watchis indeed a function defined on your view model class or a valid imported function.Check Spelling: Double-check the spelling of the callback function name provided to
@watchor the name of the decorated method.Ensure Definition: Confirm that the callback function is correctly defined within the view model class.
Use Correct Decorator Syntax: Ensure you are using the
@watchdecorator syntax correctly for your intended use case (decorating a method vs. decorating a class).
Example
Debugging Tips
Identify the component (
<ControllerName>) and the specific@watchdecorator causing the issue.Examine the arguments passed to the
@watchdecorator.If a callback name (string) is provided, verify that a method with that exact name exists on the class.
If a function reference is provided directly, ensure it's correctly defined and imported if necessary.
Use
console.log(typeof this.callbackMethodName)in the constructor orbindinglifecycle hook to check the type of the intended callback just before@watchis likely processed.Temporarily remove the problematic
@watchdecorator to confirm it's the source of the error.
Last updated
Was this helpful?