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

0

228
Views
How to type a function with parameters in typescript?

I have these interfaces and functions to manipulate data (email, password and, name) to send to my API.

interface SignUpData {
        email: string
        password: string
        name: string
    }

interface SignupProps {
    handleSignup: () => void
    errors: DeepMap<FieldValues, FieldError>
    register: UseFormRegister<FieldValues>

}

const handleSignup = ({ name, email, password }: SignUpData) => {
        api
        .post("/users", {name, email, password})
}

<SignupForm
                 
                errors={errors}
                register={register}
                handleSignup={handleSubmit(handleSignup)}
            />

However, I am getting a problem in my last line

handleSignup={handleSubmit(handleSignup)}

HandleSubmit is default of forms

It happens because:

Argument of type '({ name, email, password }: SignUpData) => void' is not assignable to parameter of type 'SubmitHandler'. Parameter types '__0' and 'data' are incompatible. The type '{ [x: string]: any; }' does not have the following properties of type 'SignUpData': email, password, namets(2345)

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