使用后运行rxjs迁移工具
rxjs-5-to-6-migrate -p src / tsconfig.app.json
我现在得到一个linting错误:
combineLatest已弃用:不赞成使用static combineLatest。
在运行迁移命令之前,这是我的代码:
this.store.combineLatest(
this.store.select(lang.getCurrent),
this.store.select(lang.getCurrentLocale)
).subscribe(([state, currentLang, locale]) => {
this._language = session.language === currentLang ? '' : currentLang;
this._locale = session.locale === locale ? '' : locale;
});
运行迁移命令后的代码:(当前显示linting错误)
import {map, combineLatest} from 'rxjs/operators';
this.store.combineLatest(
this.store.select(lang.getCurrent),
this.store.select(lang.getCurrentLocale)
).subscribe(([state, currentLang, locale]) => {
this._language = session.language === currentLang ? '' : currentLang;
this._locale = session.locale === locale ? '' : locale;
});
问题在这个stackoverflow问题中被问到,但它不够具体:Angular 6 ng lint duplicate errors and warnings, combineLatest is deprecated 。
我在这篇文章中找到了一个答案:RxJS 6: What's new and what has changed?(来自official docs):
解决方案是转换:
import { combineLatest } from 'rxjs/operators';
a$.pipe(combineLatest(b$, c$));
成:
import { combineLatest } from 'rxjs';
combineLatest(a$, b$, c$);
在rxjs 6.5中
import { combineLatest } from 'rxjs';
combineLatest([a$, b$, c$])
rxjs版本6.4.0
你应该从RxJs运算符导入map运算符,它将起作用
combineLatest(a$, b$, c$).pipe(map([a, b, c]) => treat(a, b, c))