Angular 15: error "subscribe is deprecated" still present after changes

319 views Asked by At

I use Webstorm editor and I work with Angular 15. I get the following message for subscribe function : "Deprecated symbol used" I found this post and on the rxjs site that the method has changed: Angular 11: subscribe is deprecated: Use an observer instead?

So i have updated my code :

test() {

// Recommended
    this.backendServices.getAllBox().subscribe(
        (response) => {
            console.log(response);
        },
        (error) => {
            console.log(error);
        },
        () => {
            console.log('complete');
        }
    );
}

But the message is still present : enter image description here

Then I found on google that this error can be produced by tslint and it is recommended to convert tslint by eslint. It's what I do by following this tuto :https://www.google.com/search?q=how+to+change+tslint+to+eslint&newwindow=1&sca_esv=582242121&rlz=1C1CHBF_frFR843FR843&sxsrf=AM9HkKkuhEYk7LWdKCbD7df9l3CiseljJA%3A1699960850354&ei=ElhTZeybFeK6kdUPtr2K-AM&oq=how+to+change+tslin&gs_lp=Egxnd3Mtd2l6LXNlcnAiE2hvdyB0byBjaGFuZ2UgdHNsaW4qAggAMgYQABgWGB4yCBAAGBYYHhgKMgYQABgWGB4yBhAAGBYYHkj7eVAAWJtocAF4AZABAJgBuwGgAccUqgEEMC4yMLgBA8gBAPgBAcICBBAjGCfCAgcQIxiKBRgnwgILEAAYgAQYsQMYgwHCAhEQLhiDARjHARixAxjRAxiABMICCxAuGIAEGMcBGK8BwgIOEC4YgAQYsQMYgwEY1ALCAgsQLhiDARixAxiKBcICCxAAGIoFGLEDGIMBwgIFEAAYgATCAhEQLhiABBixAxiDARjHARjRA8ICBRAuGIAEwgIIEC4YgAQYsQPCAggQABiABBixA8ICCBAuGIAEGNQCwgIIEAAYigUYsQPCAhcQLhiABBixAxiXBRjcBBjeBBjgBNgBAcICCRAAGA0YExiABMICBxAAGBMYgATCAggQABgWGB4YE-IDBBgAIEGIBgG6BgYIARABGBQ&sclient=gws-wiz-serp#fpstate=ive&vld=cid:8749a8e7,vid:fsr6CFqqsLc,st:0

This is commands : enter image description here

Angular.json et package.json have been updated as following : enter image description here enter image description here

But the error is still present.

What is missing ?

EDIT: my getAllBox method:

 getAllBox() {
    return this.http.get<ApiResponse>(this.apiUrl + '/api/site/all');
}
1

There are 1 answers

2
enno.void On

Its just the calling signature of subscribe which is deprecated.

instead of:

obs$.subscribe(() => {}, () => {}, () => {})

you should use the current recommended way:

obs$.subscribe({next:() => {},error: () => {], complete: () => {}})

From Observable.ts:

  subscribe(observer?: Partial<Observer<T>>): Subscription;
  subscribe(next: (value: T) => void): Subscription;
  /** @deprecated Instead of passing separate callback arguments, use an observer argument. Signatures taking separate callback arguments will be removed in v8. Details: https://rxjs.dev/deprecations/subscribe-arguments */
  subscribe(next?: ((value: T) => void) | null, error?: ((error: any) => void) | null, complete?: (() => void) | null): Subscription;

personal view:

For the most cases i just use the subscribe signature only with the next callback, for errors i use the catchError operator for complete i use finalize