Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

179
Views
How do I typecheck, objects in a parameter, in a typescript function

I am having issues typechecking some parameters in a function

function myfun({carengine,cartransmission})
{

   // Some code here

}

I wish to type check it so it is like this function myfun({carengine:CarEngine,cartransmission:CarTransmission})

However this does not work.

How do I typecheck these parameters?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Define the type for the structured function argument, eg

interface Car {
  carengine: CarEngine,
  cartransmission: CarTransmission
}

function myfun({ carengine, cartransmission }: Car)
{
   // Some code here
}

Typescript Playground

If you already have a Car type and only want to specify certain properties for your myfun function, you can use Pick

interface Car {
  carengine: CarEngine,
  cartransmission: CarTransmission,
  doors: number
}

function myfun({ carengine, cartransmission }: Pick<Car, "carengine" | "cartransmission">)
{
   // Some code here
}

You can also define the argument type inline but it can get messy fast

function myfun({ carengine, cartransmission }: { carengine: CarEngine, cartransmission: CarTransmission })
{
   // Some code here
}
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!