ngrx angularfire设置问题
我在Angular 7上,不断出现以下错误: 错误:22,51 TS2339:类型“Actions”上不存在属性“ofType” 在学习本教程时: 对该功能的支持是否已更改ngrx angularfire设置问题,angular,ngrx,Angular,Ngrx,我在Angular 7上,不断出现以下错误: 错误:22,51 TS2339:类型“Actions”上不存在属性“ofType” 在学习本教程时: 对该功能的支持是否已更改 @Effect() googleSignIn: Observable<Action> = this.actions.ofType(authActions.GOOGLE_LOGIN) .map((action: authActions.GoogleLogin) => action.payloa
@Effect()
googleSignIn: Observable<Action> = this.actions.ofType(authActions.GOOGLE_LOGIN)
.map((action: authActions.GoogleLogin) => action.payload)
.switchMap(payload => {
return Observable.fromPromise(this.authService.googleSignIn());
})
.catch(err => {
return Observable.of(new authActions.AuthError({ error: err.message }));
});
由于RxJs 6.x,您应该编写如下内容:
@Effect()
googleSignIn: Observable<Action> = this.actions.pipe(
ofType(authActions.GOOGLE_LOGIN),
map((action: authActions.GoogleLogin) => action.payload),
switchMap(payload => {
return Observable.fromPromise(this.authService.googleSignIn());
}),
catchError(err => {
return Observable.of(new authActions.AuthError({ error: err.message }));
}),
);
那篇教程已经有将近2年的历史了。它过时了。查找更新的学习资源。谢谢。我现在得到这个错误:错误TS2345:类型为'type of GoogleSignIn'的参数不能分配给类型为'string | ActionCreator'的参数。
src/app/modules/auth/auth.effects.ts(20,12): error TS2345: Argument of type 'type
of GoogleSignIn' is not assignable to parameter of type 'string | ActionCreator<s
tring, FunctionWithParametersType<any[], object>>'.
Type 'typeof GoogleSignIn' is not assignable to type 'ActionCreator<string, Fun
ctionWithParametersType<any[], object>>'.
Type 'typeof GoogleSignIn' is not assignable to type 'FunctionWithParametersT
ype<any[], object>'.
Type 'typeof GoogleSignIn' provides no match for the signature '(...args: any[]): object'.
import { User } from '../shared/models/user';
import * as authActions from './auth.actions';
const defaultUser = new User(null, 'GUEST');
export type Action = authActions.All;
export function authReducer(state: User = defaultUser, action: Action) {
switch (action.type) {
case authActions.GET_USER:
return { ...state };
case authActions.AUTHENTICATED:
return { ...state, ...action.payload };
case authActions.NOT_AUTHENTICATED:
return { ...state, ...defaultUser};
case authActions.GOOGLE_SIGNIN:
return { ...state, loading: true };
case authActions.AUTH_ERROR:
return { ...state, ...action.payload, loading: false };
case authActions.LOGOUT:
return { ...state, loading: true };
}
}
@Effect()
googleSignIn: Observable<Action> = this.actions.pipe(
ofType(authActions.GOOGLE_LOGIN),
map((action: authActions.GoogleLogin) => action.payload),
switchMap(payload => {
return Observable.fromPromise(this.authService.googleSignIn());
}),
catchError(err => {
return Observable.of(new authActions.AuthError({ error: err.message }));
}),
);