gpt4 book ai didi

angular - 将 NgRx 和 Angular 升级到版本 7 后无法编译

转载 作者:行者123 更新时间:2023-12-04 00:26:33 26 4
gpt4 key购买 nike

我正在将使用 NgRx 的 Angular 应用程序从 6.1.3 版升级到 7.2.15 版。运行后ng-update我的版本升级如下:

Angular - 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[]>'.

我没有使用任何非常复杂的选择器。大多数只是直接从功能商店获得值(value),并且该应用程序在升级之前就可以运行。作为其中一个组件的(简化)示例,错误指向:

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

我的选择器在哪里:

export const selectDetailMetadata = createSelector(
getMyFeatureState,
(state: MyFeatureState) => state.detailMetadata
);

在我看来,这个错误几乎就像选择器应该返回特性状态,而不是我在组件中声明为类型的状态切片。作为升级过程的一部分,我是否缺少一些需要完成的事情?

最佳答案

private store$: Store<MyFeatureState>


要么用全局状态(不是特性状态)注入(inject)存储,要么只注入(inject) Store<{}> .选择器已经进行了类型检查。
更新:仅注入(inject) Store

关于angular - 将 NgRx 和 Angular 升级到版本 7 后无法编译,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56266083/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com