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

132
Views
Defining TypeScript function taking object with unspecified number of keys

I have a function that takes an object as an input and returns an object as well. I would like to define it such that it can have any number of keys in the input or returned object.

Right now, I define it like this:

const myFunc: ({}) => ({})

Is there a good way to write it to avoid any type errors while also using the advantages that TS provides?

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

0

You can use TypeScript's Record<K, V> type to specify an object with arbitrary keys of type K and values of type V:

type MyObj = Record<string, any>;

Keys must be strings, numbers, or symbols, but values can be any type you specify. Your function would then become:

const myFunc = (obj: Record<???, ???>): Record<???, ???> => { /* ... */ };
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!