简体   繁体   English

可观察的 <void | AuthError> &#39;不可分配给&#39;Observable类型 <Action>

[英]Observable<void | AuthError>' is not assignable to type 'Observable<Action>

I keep getting the following error: error TS2322: Type 'Observable<void | AuthError>' is not assignable to type 'Observable<Action>'. Type 'void | AuthError' is not assignable to type 'Action'. Type 'void' is not assignable to type 'Action'. 我不断收到以下错误: error TS2322: Type 'Observable<void | AuthError>' is not assignable to type 'Observable<Action>'. Type 'void | AuthError' is not assignable to type 'Action'. Type 'void' is not assignable to type 'Action'. error TS2322: Type 'Observable<void | AuthError>' is not assignable to type 'Observable<Action>'. Type 'void | AuthError' is not assignable to type 'Action'. Type 'void' is not assignable to type 'Action'.

What does it mean and how can I fix it? 这是什么意思,我该如何解决?

  googleSignIn: Observable<Action> = this.actions.pipe(
    ofType(authActions.GOOGLE_SIGNIN),
    map((action: authActions.GoogleSignIn) => action.payload),
    switchMap(() => {
      return Observable.fromPromise(this.authService.googleSignIn());
    }),
    catchError(err => {
      return Observable.of(new authActions.AuthError({ error: err.message }));
    })
  );

authService.googleSignIn() authService.googleSignIn()

  googleSignIn() {
    this.logger.debug('Initialising desktop Google sign in');
    const provider = new auth.GoogleAuthProvider();
    let firstName = null;
    let lastName = null;
    return this.afAuth.auth.signInWithPopup(provider).then(async (result) => {
      if (result) {
        firstName = result.additionalUserInfo.profile['given_name'];
        lastName = result.additionalUserInfo.profile['family_name'];
        const path = `/users/${result.user.uid}/`;
        const doc = await this.firebaseService.docExists(path);
        if (!doc) {
          this.userService.processNewUser(result, firstName, lastName);
        }
        if (doc) {
          this.logger.debug(`${firstName} ${lastName} is a returning desktop user`);
        }
      }
    }).catch((error) => {
      this.simpleModalService.displayMessage('Oops', error.message);
    });
  }

If you are using ngrx v8 you can do like this 如果您使用的是ngrx v8,则可以这样做

The problem you have is you have to return an action from you effect 您遇到的问题是您必须从您的结果中退回一个动作

 getPost$ = createEffect(() =>
    this.actions$.pipe(
      ofType(PostActions.LoadPost),
      switchMap(action => {
        return this.postService
          .getPost(action.postId)
          .pipe(
            map(
              (post: IPost) => PostActions.LoadPostSuccess({ post }), // here is what you need to return
              catchError(errors => of(PostActions.LoadPostFail(errors)))
            )
          );
      })
    )
  );

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 输入“可观察的<void> ' 不可分配给类型 'void | 行动 | 可观察的<action> '. 添加效果时</action></void> - Type 'Observable<void>' is not assignable to type 'void | Action | Observable<Action>'. when adding an effect 输入&#39;可观察的<Object> &#39; 不可分配给类型 &#39;Observable<IUser[]> &#39; - Type 'Observable<Object>' is not assignable to type 'Observable<IUser[]>' 不可分配给“可观察”类型 <task> &#39;。角4 - is not assignable to type 'Observable<task>'.Angular 4 RXJS可观察的枚举类型,类型为“可观察” <Type> &#39;不可分配给&#39;Type&#39;类型 - RXJS Observable enum type, Type 'Observable<Type>' is not assignable to type 'Type' RxJs管道和可调运算符`map`:'this'类型的'this'上下文不能赋值给'Observable <{}>'类型的方法'this' - RxJs pipe and lettable operator `map`: 'this' context of type 'void' is not assignable to method's 'this' of type 'Observable<{}>' 类型“可观察” <boolean | “”> &#39;不可分配给&#39;Observable类型 <boolean> &#39;TS2322 - Type 'Observable<boolean | “”>' is not assignable to type 'Observable<boolean>' TS2322 输入&#39;可观察的<HttpEvent<T> &gt;&#39; 不可分配到类型 &#39;Observable<T> &#39; - Type 'Observable<HttpEvent<T>>' is not assignable to type 'Observable<T>' 无法将“订阅”类型分配给“可观察”类型 <Exercise[]> “ - Type 'Subscription' is not assignable to type 'Observable<Exercise[]>' 输入&#39;可观察的<Response> &#39; 不可分配给类型 &#39;Observable <HttpResponse<Blob> &gt;&#39; - Type 'Observable<Response> ' is not assignable to type 'Observable<HttpResponse<Blob>>' 无状态 observable 服务中的错误:键入“Observable”<Course[]> &#39; 不可分配给类型 &#39;Observable<Course> &#39; - Error in stateless observable service: Type 'Observable<Course[]>' is not assignable to type 'Observable<Course>'
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM