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

128
Views
Function to wrap function and provide one property of object

I want to create a new function from an initial function, with the initial function taking a single object argument and the new function taking the same single object argument apart from populated fields. I've got something like this so far:

function returnNewFunc<TArg extends { b?: string }>(
  initialFunc: (arg: TArg) => void
) {
  const newFunc = (arg: Omit<TArg, "b">) =>
    initialFunc({ ...arg, b: "hello" });

  return newFunc
}

const funcA = ({ b, c }: { b: string; c: string }) => {
  console.log(b, c);
};
const funcB = returnNewFunc(funcA)
funcB({c: "test"}) // funcB should have 'c' as the only field in its argument

The issue here is I get a could be instantiated with a different subtype of constraint typescript error, so I must be doing something wrong.

about 4 years ago · Santiago Trujillo
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!