I'm having issues converting a line of code to Typescript which I'm trying to learn. I'm getting some error lines related to my useReducer hook. I've commented out the lines above and under the issues with the error message I'm receiving.
const ACTIONS = {
ADD_DIGIT: "add-digit",
CLEAR: "clear",
DELETE_DIGIT: "delete-digit",
CHOOSE_OPERATION: "choose-operation",
EVALUATE: "evaluate",
};
// Binding element 'type' implicitly has an 'any' type.
const reducer = (state: any, { type, payload }) => {
// ^^ERROR
switch (type) {
case ACTIONS.ADD_DIGIT:
return {
...state,
// ##Cannot find name 'currentOperand'
currentOperand: `${currentOperand || ""}${payload.digit}`,
// ^^ERROR
};
}
};
const App: React.FC = () => {
const [{ currentOperand, previousOperand, operation }, dispatch] = useReducer(
reducer,
{}
);
dispatch({ type: ACTIONS.ADD_DIGIT, payload: { digit: 1 } });
return ()
}