AUR0772: Invalid @watch decorator config. Expected an expression or a fn but received null/undefined.
Description
This error occurs when using the @watch decorator, but the required first argument (the expression to watch) is null or undefined. The @watch decorator needs a valid target to observe for changes.
Cause
The primary cause is providing null or undefined as the first argument to the @watch decorator.
import{ watch }from'@aurelia/runtime-html';exportclassMyViewModel{ // Incorrect: Passing null as the expression@watch(null)nullWatchHandler(){/* ... */} // Incorrect: Passing undefined as the expression@watch(undefined)undefinedWatchHandler(){/* ... */} // Incorrect: Passing a variable that is null/undefined@watch(someVariableThatMightBeNull)variableWatchHandler(){/* ... */}}
Solution
Ensure that the first argument provided to the @watch decorator is always a valid string representing the property path or expression to watch, or a function that selects the value to watch.
Provide a Valid Expression: Replace null or undefined with a string expression (e.g., 'myProperty', 'user.address.street') or a function.
Check Variables: If using a variable for the expression, ensure it holds a valid string or function before being used in the decorator. Decorator arguments are evaluated at class definition time.
Example
Debugging Tips
Verify the arguments passed to the @watch decorator directly in your component's code.
Ensure any variables used as arguments to @watch are defined and have the correct type (string or function) at the time the class is defined. Remember that decorator code runs early in the class definition process.