Redux-saga: Typescript - Call mock api with call effect

Created on 25 Feb 2018  路  3Comments  路  Source: redux-saga/redux-saga

Hi,
It's my first issue ans I didn'T find a way to label it, sorry. I'm trying to call a mock API and i got this error:
error TS2345: Argument of type 'Promise'.
Type 'Promise Property 'context' is missing in type 'Promise

The version of redux-saga is: "^0.16.0"

Here the mock API:

    getAllMembersAsync() : Promise<Program[]> {
        const promise : Promise<Array<Program>> = new Promise((resolve, reject) => {
                var members : Array<Program>;

                members = ProgramsData.map((currentProgram) => {
                    var program : Program = new Program();

                    program.code = currentProgram.code;
                    program.nom = currentProgram.nom;
                    program.cours = currentProgram.cours;

                    return program;
                });

                resolve(members);
            // });
        });
        return promise;
    }

And here my saga:

import {call, put, takeLatest} from 'redux-saga/effects';
import { receivedPrograms, FetchPrograms, FETCH_PROGRAMS } from '../actions/programActions';
import { Program } from '../model/program';
import programAPI from '../api/programAPI';

function* fetchPrograms(action: FetchPrograms) {
    let programs: Array<Program>;
    programs = yield call(programAPI.getAllMembersAsync());
    yield put(receivedPrograms(programs));
}

Can someone tell my what i'm not doing correctly ?

thanks alot guys !

Typings

Most helpful comment

I have nearly zero experience with TS, but maybe you could try this:

    programs = yield call(programAPI.getAllMembersAsync);

call is responsible for actually executing ur function, so invoking it here is probably not what u were looking for.

All 3 comments

I have nearly zero experience with TS, but maybe you could try this:

    programs = yield call(programAPI.getAllMembersAsync);

call is responsible for actually executing ur function, so invoking it here is probably not what u were looking for.

Thanks a lot @Andarist, my nearly zero experience with TS in nearer of zero than yours.

thanks again !

I guess this can be closed then. Glad it helped :)

Was this page helpful?
0 / 5 - 0 ratings