bni*_*yer 4 ngrx angular-cli angular angular7
我正在将使用 NgRx 的 Angular 应用程序从版本 6.1.3 升级到 7.2.15。运行后ng-update我的版本升级如下:
角度 - 6.1.3 -> 7.2.15
NgRx - 6.1.0 -> 7.4.0
RxJS - 6.2.2 -> 6.5.2
rxjs-compat(第三方组件需要) - 6.2.2 -> 6.5.2
在升级编译失败并返回以下错误的变体后,尝试构建或提供应用程序时,对于所有使用选择器的地方:
Types of parameters 'source$' and 'source' are incompatible.
Type 'Observable<MyFeatureState>' is not assignable to type
src/app/my-feature/detail/detail.component.ts(84,45): error TS2345: Argument of type '(source$: Observable<State>) => Observable<DetailMetadata[]>' is not assignable to parameter of type 'OperatorFunction<MyFeatureState, DetailMetadata[]>'.
Run Code Online (Sandbox Code Playgroud)
我没有使用任何非常复杂的选择器。大多数只是直接从功能商店获取值,并且应用程序在升级之前就可以运行。作为其中一个组件的(简化)示例,错误指向:
Types of parameters 'source$' and 'source' are incompatible.
Type 'Observable<MyFeatureState>' is not assignable to type
src/app/my-feature/detail/detail.component.ts(84,45): error TS2345: Argument of type '(source$: Observable<State>) => Observable<DetailMetadata[]>' is not assignable to parameter of type 'OperatorFunction<MyFeatureState, DetailMetadata[]>'.
Run Code Online (Sandbox Code Playgroud)
我的选择器在哪里:
import { MyFeatureState } from "../store/reducers";
import * as fromFeature from "../store/selectors";
@Component({
selector: "my-detail",
template: `
<my-detail-list [detailMetadata]="detailMetadata$ | async"></my-detail-list>
`
})
export class DetailComponent implements OnInit {
detailMetadata$: Observable<DetailMetadata[]>;
constructor(private store$: Store<MyFeatureState>) {}
ngOnInit() {
this.detailMetadata = this.store$.pipe(
select(fromFeature.selectDetailMetadata)
);
}
}
Run Code Online (Sandbox Code Playgroud)
在我看来,这个错误几乎就像是选择器应该返回特征状态而不是我在组件中声明为类型的状态切片。作为升级过程的一部分,我缺少什么需要完成的事情吗?
private store$: Store<MyFeatureState>
要么使用全局状态(不是功能状态)注入商店,要么只注入Store<{}>. 选择器已经进行了类型检查。
| 归档时间: |
|
| 查看次数: |
691 次 |
| 最近记录: |