• Jobs
  • About Us
  • professionals
    • Home
    • Jobs
    • Courses and challenges
  • business
    • Home
    • Post vacancy
    • Our process
    • Pricing
    • Assessments
    • Payroll
    • Blog
    • Sales
    • Salary Calculator

0

187
Views
Converting Javascript to Typescript useReducer hook

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 ()

}

about 3 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Our process Sales
Legal
Terms and conditions Privacy policy
© 2025 PeakU Inc. All Rights Reserved.

Andres GPT

Recommend me some offers
I have an error