Warm tip: This article is reproduced from serverfault.com, please click

"subscribe()" is deprecated when using "of(false)"

发布于 2020-12-01 01:42:13

I am trying to use of but my editor is saying that it is deprecated. How can I get this to working using of?

  public save(): Observable<ISaveResult> | Observable<boolean> {
    if (this.item) {
      return this.databaseService.save(this.userId, this.item)
    }
    return of(false)
  }
  public componentSave() {
    const sub = this.userService
      .save()
      .subscribe(val => {
        // This callback shows the below error in the editor
      })
  }

When I use this, I get the following error in my editor:

@deprecated — Use an observer instead of a complete callback

'(next: null, error: (error: any) => void, complete: () => void): Subscription' is deprecated
Expected 2-3 arguments, but got 1.
Questioner
Get Off My Lawn
Viewed
0
Andrew Alderson 2020-12-01 11:28:53

Never mind I think I found the problem. Change the return type of the save function from

public save(): Observable<ISaveResult> | Observable<boolean>

to

public save(): Observable<ISaveResult | boolean>