Khushi Sharma Khushi Sharma - 13 days ago 9
TypeScript Question

Argument of type 'void' is not assignable to parameter of type 'Action'

i'am new to Typescript and using VSCode.

Getting following Error:

*[ts] Argument of type 'void' is not assignable to parameter of type 'Action'.
(parameter) action: void


Code:

loadItems() {
return this.Apiname.find()
.map(
(data) => console.log("data:", data)
)
.map(
payload => ({
type: 'LOAD_ITEMS',
payload: payload
},
)
)
.subscribe(
action => this._store.dispatch(action)//Error
);
};


Any help will be very helpfull.

Answer

Your map statement contains trailing ,, which could be the problem. I'd adjust the code like that:

return this.Apiname.find()
    .do( (data) => console.log("data:", data) )
    .map(
        payload => ({
            type: 'LOAD_ITEMS',
            payload: payload
        //},)
        })
    )
    .subscribe(
        action => this._store.dispatch(action) //Error
    );

now action is of type { type: string, payload: ... }

NOTE: for side affects, like console.log we are provided with an .do operator - http://reactivex.io/documentation/operators/do.html

Comments