声明类型为string的变量时(&a);Post,这意味着该变量拥有Post的所有方法和字符串的所有方法。这可能不是你想要的。
您希望您的操作有一个标识符(类型为string)和一个post。您可以为此声明一个接口,或者您的操作可以有多个属性,如:
export class UpdatePost implements Action {
readonly type = UPDATE_POST
constructor(public id: string, public payload: Post ) { }
}
因此,你可以这样写:
@Effect()
editPost$: Observable<Action> = this.actions$
.ofType(PostActions.UPDATE_POST)
.switchMap(action => {
return this.postService.editPost(action.id, action.post);
})
.map(editedpost => ({type: PostActions.UPDATE_POST_SUCCESS, payload: editedpost}))
}