我正在尝试调用模拟API,但是我遇到了这个错误: 错误TS2345:类型'Promise'的参数不能分配给'CallEffectNamedFn< {[x:string]:Func0;类型的参数。 },string>'。 类型'Promise'不能分配给'{context:{[x:string]:Func0; }; fn:string; }”。 “承诺”类型中缺少属性“上下文”。
redux-saga的版本是:“^ 0.16.0” tsConfig: “目标”:“es6”, “lib”:[“es6”,“dom”],
这里是模拟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;
}
这是我的传奇:
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));
}
有人可以告诉我我做的不正确吗?
非常感谢你们!