我是新来的打字稿我正在实现react useContext 和useReducer。我正在遵循教程,但出现错误Parameter 'action' implicitly has an 'any' type.
在我的减速器功能中。
减速机功能
function reducer(state, action) { // error Parameter 'action' implicitly has an 'any' type.
return { count: state.count + 1 }
}
计数提供者
const [state, dispatch] = useReducer(reducer, {
count: 0
})
您必须将操作类型指定为any 或以通用形式执行。如果您想构建操作,您可以创建一个界面。
function reducer(state, action: { [key: string]: string|number }) { // error Parameter 'action' implicitly has an 'any' type.
return { count: state.count + 1 }
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)