这是我的selector.ts
export interface ITestState {
value: number;
}
export interface IReduxState {
test: ITestState;
}
export const selectTest = (state: IReduxState) => state.test;
export const selectTestValue = createSelector(
selectTest,
(state: ITestState) => state.value
);
Ï如果我尝试在 app.component.ts
中使用它
像这样
constructor(private store: Store) {
this.vaschal$ = store.select(selectTestValue);
}
我收到以下错误
No overload matches this call.
Overload 1 of 9, '(mapFn: (state: object) => number): Observable<number>', gave the following error.
Argument of type 'MemoizedSelector<IReduxState, number, DefaultProjectorFn<number>>' is not assignable to parameter of type '(state: object) => number'.
Types of parameters 'state' and 'state' are incompatible.
Property 'test' is missing in type '{}' but required in type 'IReduxState'.
Overload 2 of 9, '(key: never): Observable<never>', gave the following error.
Argument of type 'MemoizedSelector<IReduxState, number, DefaultProjectorFn<number>>' is not assignable to parameter of type 'never'
角度版本11.2.4
我做错了什么?
答案 0 :(得分:1)
您需要将根存储状态通知Store
:
constructor(private store: Store<IReduxState>) {
this.vaschal$ = store.select(selectTestValue);
}