How to prevent Angular Signal references being used instead of Signal Values?

114 views Asked by At

I am enthralled with Angular Signals, exactly what I want out of the library, but one thing that I have commonly found is that I accidentally am calling a signal reference somewhere (in a template block, or in the component somewhere) instead of calling the signal value. For example:

public conditionalSignal = signal(false);
...

// Accidentally using the reference:
if (conditionalSignal) {
  ...
}

// Instead of something like this:
if (conditionalSignal()) {
  ...
}

I was hoping someone had a ESLint plugin or Angular compiler option that they knew about that would help prevent this situation from happening. This obviously doesn't occur when I am generating new signals, but when refactoring old components to use a signal based methodology, it has happened more than once, and it's something that I would like to prevent if at all possible.

I also recognize that my first example is completely valid code, but I can almost guarantee that I'd never do that intentionally.

0

There are 0 answers