[Fixed] Angular 11: subscribe is deprecated: Use an observer instead?

Issue

My tslint gone crazy? It gives warning for every subscribtion I made in whole app. It doesn’t matter if I use old or new syntax it still says that subscribe is deprecated… How to write a subscription that will not be deprecated?

That’s what was ok till today:

something.subscribe((user: User) => {
        this.userProviderService.setUserId(user.userId);
        this.proceed = true;
      });

I tried new syntax but makes no change:

something.subscribe({
        next: (user: User) =>  {
          this.userProviderService.setUserId(user.userId);
          this.proceed = true;
        },
        complete: () => {},
        error: () => {}
      });

This is exactly what it’s saying:

(method) Observable.subscribe(next?: (value: Object) => void,
error?: (error: any) => void, complete?: () => void): Subscription (+4
overloads) @deprecated — Use an observer instead of a complete
callback

@deprecated — Use an observer instead of an error callback

@deprecated — Use an observer instead of a complete callback

subscribe is deprecated: Use an observer instead of a complete
callback (deprecation)tslint(1)

So how do I subscribe to things now?

Solution

I just looked up TSLint (v1.3.3) at VS Code extenstions tab. It says:

❗IMPORTANT: TSLint has been deprecated in favor of ESLint.

As I disabled TSLint and installed ESLint, all warnings related to subscribtions dissapeared.

Cheers!

Leave a Reply

(*) Required, Your email will not be published