redux-saga + typescript 使用 takeLatest 报错
代码
import { takeLatest, put, select } from 'redux-saga/effects'
import { GET_COMMENT_LIST } from './actionTypes'
import { fetch } from '../../../common/index'
import { initCommentList } from './actionCreators'
interface IAction {
commentType?: string,
page?: number | string
}
function* axiosCommentList({ commentType, page }: IAction) {
const user = yield select((state: { user: { user: string } }) => state.user.user)
try {
const formData = {
type: commentType,
page: page,
pageSize: 10,
create_user: user,
to_user: user
}
const {
data: {
data: { result, total }
}
} = yield fetch.post('/api/comment/getusercommentlist', formData)
yield put(initCommentList(result, total))
} catch (e) {
console.log(e.message)
}
}
export function* getCommentList() {
yield takeLatest(GET_COMMENT_LIST, axiosCommentList)
}
takeLatest 会报错
No overload matches this call.
The last overload gave the following error.
类型“string”的参数不能赋给类型“TakeableChannel<unknown>”的参数。
但是我把 IAction 改下就不会报错了
interface IAction {
commentType?: string,
page?: number | string,
[x: string]: any
}
=.=有没有大佬遇到过
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
解决了
IState 继承下官方 Action 即可