Search code examples
javascriptangulartypescriptrxjs

Observable `of` deprecated. What is the equivalent?


In my case, I have an access token, and should that token exist, I would return it as an observable of type string:

if (this.accessToken){
  return of(this.accessToken);
}

Due to a recent update, I noticed that of is deprecated with the following message:

of is deprecated: use scheduled instead 'scheduled([a, b, c], scheduler)' (deprecation)

The new syntax is quite verbose, would anyone know the equivalent scheduled version of the same simple of? The keyword name makes it difficult to search for information on it.

Thanks!


Solution

  • Only the overloads that accept a scheduler are deprecated. The variant that you are using is not deprecated, see https://github.com/ReactiveX/rxjs/blob/master/packages/rxjs/src/internal/observable/of.ts