简体   繁体   中英

TypeError while Implement startWith() operator in rxjs

I am quite a beginner at angular and I am just trying to create an Observable and run it automatically just the first time when a particular condition is not met.

but typescript throws some errors while I use startWith() and I don't understand what to do now?

this.obsearable$ = this.id ? from(this.pt.get(this.id)) : from([]).pipe(startWith())

Error: Argument of type 'Observable' is not assignable to parameter of type 'OperatorFunction<any, unknown>'.

Type 'Observable' provides no match for the signature '(source: Observable): Observable'.ts(2345)

The startWith() operator is intended for observables that may not emit an initial value. In the case of your example, from() immediately emits the value contained inside its parameter, so there is no need to use startWith() .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM