传奇观察者和打字稿问题
saga watcher and typescript issue
在观察者中定义多个传奇时遇到打字稿问题,我经常看到这种模式:
// foo.JS
export function *fooSagas() {
yield all([
takeEvery("FOO_A", fooASaga),
takeEvery("FOO_B", fooBSaga),
]);
}
但是当我尝试在打字稿文件中执行此操作时,我得到以下信息:
// foo.TS
export function *fooSagas() {
yield all([
takeEvery("FOO_A", fooASaga),
/*
all subsequent calls throw this typescript error:
The last overload gave the following error.
Argument of type 'string' is not assignable to parameter of type 'TakeableChannel<unknown>
effects.d.ts(291, 17): The last overload is declared here.
*/
takeEvery("FOO_B", fooBSaga),
]);
}
发帖是为了节省别人的时间...
显然这只是打字稿。
在每行之前添加 // @ts-ignore,一切正常
yield all ([
// @ts-ignore
takeLatest(ACT.todo.saga.create, create),
// @ts-ignore
takeLatest(ACT.todo.saga.retrieve, retrieve),
// @ts-ignore
takeLatest(ACT.todo.saga.update,update),
// @ts-ignore
takeLatest(ACT.todo.saga.delete,del),
// @ts-ignore
takeLatest(ACT.todo.saga.list, list)
])
你可以在这里找到更好的答案
https://github.com/redux-saga/redux-saga/issues/1883
在 chenghw 于 2019 年 7 月 9 日发表的评论中。
In the generator, you are currently declaring the action as { payload: ICredential }
without a type. If you declare the type, I think you will get rid of that error...so something like this...{ type: typeof types.USER_LOGIN_REQUEST; payload: ICredential; }
在观察者中定义多个传奇时遇到打字稿问题,我经常看到这种模式:
// foo.JS
export function *fooSagas() {
yield all([
takeEvery("FOO_A", fooASaga),
takeEvery("FOO_B", fooBSaga),
]);
}
但是当我尝试在打字稿文件中执行此操作时,我得到以下信息:
// foo.TS
export function *fooSagas() {
yield all([
takeEvery("FOO_A", fooASaga),
/*
all subsequent calls throw this typescript error:
The last overload gave the following error.
Argument of type 'string' is not assignable to parameter of type 'TakeableChannel<unknown>
effects.d.ts(291, 17): The last overload is declared here.
*/
takeEvery("FOO_B", fooBSaga),
]);
}
发帖是为了节省别人的时间... 显然这只是打字稿。
在每行之前添加 // @ts-ignore,一切正常
yield all ([
// @ts-ignore
takeLatest(ACT.todo.saga.create, create),
// @ts-ignore
takeLatest(ACT.todo.saga.retrieve, retrieve),
// @ts-ignore
takeLatest(ACT.todo.saga.update,update),
// @ts-ignore
takeLatest(ACT.todo.saga.delete,del),
// @ts-ignore
takeLatest(ACT.todo.saga.list, list)
])
你可以在这里找到更好的答案 https://github.com/redux-saga/redux-saga/issues/1883 在 chenghw 于 2019 年 7 月 9 日发表的评论中。
In the generator, you are currently declaring the action as
{ payload: ICredential }
without a type. If you declare the type, I think you will get rid of that error...so something like this...{ type: typeof types.USER_LOGIN_REQUEST; payload: ICredential; }