Reputation: 103
I'm trying to call a mock API and i got this error: error TS2345: Argument of type 'Promise' is not assignable to parameter of type 'CallEffectNamedFn<{ [x: string]: Func0; }, string>'. Type 'Promise' is not assignable to type '{ context: { [x: string]: Func0; }; fn: string; }'. Property 'context' is missing in type 'Promise'.
The version of redux-saga is: "^0.16.0" tsConfig: "target": "es6", "lib": ["es6", "dom"],
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 !
Upvotes: 1
Views: 1958
Reputation: 103
It's a typo... here the solution
programs = yield call(programAPI.getAllMembersAsync);
Upvotes: 2