Skip to content

no-unbound-methods throws errors when passing Angular signals to an operatorΒ #209

@dkimmich-onventis

Description

@dkimmich-onventis

I have a custom RxJS operator which expects an Angular signal as a parameter. Here is a simplified version:

export function indicateLoading<T>(target: WritableSignal<boolean>): ((source: Observable<T>) => Observable<T>) {
  return (source: Observable<T>): Observable<T> => {
    target.set(true);

    return source.pipe(
      finalize(() => target.set(false)),
    );
  };
}

However when I use this operator, the rxjs-x/no-unbound-methods rule throws an error:

@Injectable()
export class MyAngularService {
  private readonly http = inject(HttpClient);
  private readonly isLoading = signal(false);

  doRequest$(url: string) {
    return this.http.get(url).pipe(indicateLoading(this.isLoading));
    //                                             ~~~~~~~~~~~~~~
    //                                             ESLint: Unbound methods are forbidden. (rxjs-x/no-unbound-methods)
  }
}

When binding the signal via this.isLoading.bind(this), the .set function is not available anymore and the operator crashes at runtime. So the only option is to disable the rule.

I suspect the reason behind this is that to read a value from an Angular signal, it needs to be called like a function.

Is there a way for the rule to distinguish between "pure" functions, and other objects like Signals which have extended functionality? If yes, maybe it makes sense to introduce an option to the rule to filter them out.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions