【问题标题】:ngrx: Supplied parameters do not match any signature of call targetngrx:提供的参数与调用目标的任何签名都不匹配
【发布时间】:2017-02-25 17:56:54
【问题描述】:

我正在使用 ngrx/效果。

在将 rxjs5.0.0-beta.12 更新为 5.0.0-rc.1 后,我的 IDE WebStorm 为我提供了下面的错误(红色下划线)。当我运行我的应用程序时,终端中也会显示相同的错误。

提供的参数与调用目标的任何签名都不匹配。

  @Effect() updateProfile$ = this.actions$
    .ofType(ProfileActions.PROFILE_UPDATE_PROFILE)
    .map<string>(toPayload)
    .switchMap(name => this.profileService.updateProfile(name)
      .map(name => ({ type: ProfileActions.PROFILE_UPDATE_PROFILE_SUCCESS, payload: name }))
      .catch(error => Observable.of({ type: ProfileActions.PROFILE_UPDATE_PROFILE_FAIL, payload: error }))
    );

.

  updateProfile(name: string): Observable<string> {
    return Observable.of(name);
  }
  • 每当我使用map&lt;string&gt;(toPayload) 时都会发生此错误。我尝试改成.map&lt;any&gt;(action =&gt; action.payload),还是一样的错误。

  • 没有map&lt;string&gt;(toPayload) 的效果不会给出 错误。

虽然它给了我错误,但应用程序仍然运行良好。

如何解决这个问题?

【问题讨论】:

    标签: angular typescript rxjs5 ngrx


    【解决方案1】:

    在 rxjs 5.0.0-rc.1 中,所有运算符的泛型类型参数都被更改为首先接受源 observable 的类型。

    您需要相应地更改 map 运算符调用:

    actions$
      .ofType(ProfileActions.PROFILE_UPDATE_PROFILE)
      .map<Action, string>(toPayload)
    

    【讨论】:

    • 只需添加来自 Gitter 的 Mike 的话,Action 来自 import { Action } from '@ngrx/store';。或者.map&lt; ProfileActions, string&gt;(toPayload) 也可以。
    猜你喜欢
    • 2016-06-09
    • 2017-04-28
    • 2017-08-24
    • 2017-07-26
    • 2018-03-31
    • 2017-05-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多