Операторы Rxjs: критические изменения - PullRequest
2 голосов
/ 03 ноября 2019

Похоже, что-то изменилось в версии Rxjs и возникли реальные проблемы при попытке переделать какой-то старый код.

Из того, что я прочитал в других постах здесь, мне кажется, что мне нужно использовать pipe, но когда я пытаюсь пересмотреть кодЗатем я получаю сообщение о типе.

Использование «rxjs»: «6.5.2», «rxjs-compat»: «6.5.2»,

Будем благодарны за любые предложения или помощь.

Текущий код

import { Observable, combineLatest, of } from 'rxjs';
import { switchMap } from 'rxjs/operators';

currentUserRoles: Array<string>;
currentUserRolesData: Array<Role> = [];
allRoles: Array<Role>;
combineRoles$: Observable<Role[]>;

Это говорит о том, что свойство 'switchMap' не существует для типа 'Наблюдаемый <[{} [], {} []]>'.

async setCurrentUser(user: User): Promise<any> {
    this.currentUserRoles = user.roles;

    const rolesWithCustomerId = this.afs.collection('roles', ref =>
        ref.where('customerId', '==', user.customerId)
    );
    const rolesWithUserId = this.afs.collection('roles', ref =>
        ref.where('customerId', '==', user.id)
    );
    this.combineRoles$ = combineLatest(
        rolesWithCustomerId.valueChanges(),
        rolesWithUserId.valueChanges()
    ).switchMap((cities: [Role[], Role[]]) => {
        // tslint:disable-next-line:no-shadowed-variable
        const [rolesWithCustomerId, rolesWithUserId] = cities;
        const combined = rolesWithCustomerId.concat(rolesWithUserId);
        return Observable.of(combined);
    });
}

Пересмотренный код Тип ошибки «Наблюдаемый» нельзя назначить типу «Наблюдаемый»

async setCurrentUser(user: User): Promise<any> {
  this.currentUserRoles = user.roles;

  const rolesWithCustomerId = this.afs.collection('roles', ref =>
    ref.where('customerId', '==', user.customerId)
  );
  const rolesWithUserId = this.afs.collection('roles', ref =>
    ref.where('customerId', '==', user.id)
  );
  this.combineRoles$ = combineLatest(
    rolesWithCustomerId.valueChanges(),
    rolesWithUserId.valueChanges()
  )
  .pipe(switchMap((cities: [Role[], Role[]]) => {
    // tslint:disable-next-line:no-shadowed-variable
    const [rolesWithCustomerId, rolesWithUserId] = cities;
    const combined = rolesWithCustomerId.concat(rolesWithUserId);
    return Observable.of(combined);
  }));
}
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...