Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 240
Khushi Avatar asked Oct 21 '25 13:10

Khushi


1 Answers

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

like image 100
Radim Köhler Avatar answered Oct 23 '25 08:10

Radim Köhler



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!