管道运算符不支持:Angular[Typescript] - rxjs - combineLatest

pipe operator not supported with : Angular[Typescript] - rxjs - combineLatest

有问题的代码

import { Injectable } from '@angular/core';
import { AccountingTransactionsStoreService } from './accounting-transactions-store.service';
import { GeneralLedgerAccountsStoreService } from './general-ledger-accounts-store.service';
import { distinctUntilChanged, map, combineLatest } from 'rxjs/operators';

@Injectable({
  providedIn: 'root'
})
export class AccountingReportsStoreService {


  constructor(
    private accountingTransactionsStore: AccountingTransactionsStoreService,
    private   generalLedgerAccountsStore: GeneralLedgerAccountsStoreService) 
    {}

  readonly generalLedgerAccountsTransaction$
    = combineLatest(
      this.accountingTransactionsStore.selectedPeriodAccountingTransactionsFlate$,
      this.generalLedgerAccountsStore.selectedOrganizationGeneralLedgerAccountsTree$)
      .pipe(distinctUntilChanged())
      .pipe(
        map(([transactionsFlat, accountsTree]) => {
          if (transactionsFlat && accountsTree)
            return [];
          else return [];
        })
      )
}

错误

Property 'pipe' does not exist on type ' OperatorFunction < unknown , [ unknown , AccountingTransactionFlatInterface [ ] , GeneralLedgerAccountInterface [ ] ] > ' .

怎么了?

import { distinctUntilChanged, map, combineLatest } from 'rxjs/operators';

为什么?

真的不确定,但我看起来是关于函数定义重载

更新自 ❤

combineLatest exists both as an operator and a function cresting an observable from multiple others. The operator version is deprecated, however. Depending on the import you get one or the other.

如何解决

'rxjs'[=导入combineLatest 58=] 不是来自 'rxjs/operators'

import { distinctUntilChanged, map } from 'rxjs/operators';
import { combineLatest} from 'rxjs';

我是如何找到解决方案的?

  • 删除了 rxjs 导入
  • 偶然使用了vscode添加了所有缺失的导入(我喜欢反复试验)

我学到了什么?有模式吗?

  • 是又不是,这不是花样,而是诡计!‍♀️
  • 尝试删除导入
  • 并使用添加所有缺失的导入
  • 然后让VSCode决定导入什么
  • 然后观察差异
  • 那就用我的判断吧
  • 因为VSCode比我更了解我的代码 ‍♀️