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.
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) // no error
);
now action is of type { type: string, payload: ... }
NOTE: for side effects, like printing with console.log, ReactiveX provides .do operator - see http://reactivex.io/documentation/operators/do.html
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With