error TS2339: Property 'takeUntil' does not exist on type 'Observable' and other rxjs v.6 errors

前端 未结 1 1841
一生所求
一生所求 2020-12-15 09:23

I just recently updated A LOT of packages in my angular project.

Old package.json:

{
  \"name\": \"data-jitsu\",
  \"version\": \"0.0.0\",
  \"licens         


        
1条回答
  •  醉梦人生
    2020-12-15 10:01

    It looks like your operators are still chained in rxjs 5.x fashion.

    So to recap what changed in rxjs6 :

    1. Imports are different. Now, you should import Observable, Subject, BehaviorSubject etc. AND methods that were in 'rxjs/add/observable' differently. So all of these must be imported from 'rxjs'. For example :

      import {Observable, Subject, of, from} from 'rxjs';

      Alternatively, all operators like map, concat, do (which now is called tap) etc. are to be imported from rxjs/operators. so something like :

      import { map, tap, takeUntil} from 'rxjs/operators';

      I think your imports are pretty sane.

    2. You must use pipes instead of chaining your operators. For instance, in your all-matches.components.ts, line 33, if you replace : this.authService.getCurrentUser().takeUntil(this.ngUnsubscribe).subscribe(user=>{

      by

      this.authService.getCurrentUser().pipe(takeUntil(this.ngUnsubscribe)).subscribe(user=>{

      your takeUntil error will disappear.

      In the same fashion, instead of Observable.of(true), you should import of operator and use of(true).

      You can try this in your authorization.service.ts file. All the "of errors" will be fixed.

      maybe you should inspect this

    3. Concerning the import errors regarding custom files, please check the files actually exist. For example :

      ERROR in src/app/app.module.ts(6,38): error TS2307: Cannot find module './api-keys'

      related to

      import { masterFirebaseConfig } from './api-keys'

      is normal, since this file './api-keys' doesn't exist. PS: maybe you don't have these errors if keys are not stored in git, if so ignore this.

    4. Finally, about AngularFire5.0, you should use one of the operators :

      Db.list('items').subscribe(console.log)

      becomes (with valueChanges method) :

      Db.list('items').valueChanges().subscribe(console.log)

      More info : https://github.com/angular/angularfire2/blob/master/docs/version-5-upgrade.md

    Good luck!

    0 讨论(0)
提交回复
热议问题