0

带有问题的代码

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 [];
        })
      )
}

错误

'OperatorFunction <未知,[未知,AccountingTransactionFlatInterface [],GeneralLedgerAccountInterface []]>'类型上不存在属性'管道'。

4

1 回答 1

0

怎么了?

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

为什么 ?

对于真正的不确定,但我看起来像是关于功能定义重载

来自❤ Ingo Burk的更新

combineLatest 既作为一个运算符存在,也作为一个从多个其他对象中获取一个可观察对象的函数存在。但是,操作员版本已被弃用。根据导入,您会得到一个或另一个。

如何解决

“rxjs”而不是从“rxjs/operators”导入combineLatest

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

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

  • 删除了 rxjs 导入
  • 使用 vscode意外添加了所有缺少的导入(我通过反复试验来准备)
  • 在此处输入图像描述

我学到的是 ?有图案吗?

  • 是与否,这不是一种模式,而是一种技巧!‍♀️</li>
  • 尝试删除导入
  • 并使用添加所有缺少的导入
  • 然后让VSCode决定要导入什么
  • 然后观察差异
  • 然后用我的判断。
  • 因为VSCode比我更了解我的代码 ‍♀️</li>
于 2019-11-11T05:51:14.577 回答