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

211
Views
Typescript generics and returning functions

I have a function that accepts another function as an argument, and returns a function having the same input type signature, but void instead of whatever output type the inner function had. The actual code does some other things, but here's the dumbed down version of it. I just can't seem to get the types right. Here's what I have so far (I'm aware it's wrong):

export function foo<Type>(func : (_ : Type) => any) {
  return function bar(...args : Type) : void {
    func.apply(null, args)
  }
}

The first line doesn't really capture what I want it to - the entire argument list of func should be Type, not just the first argument. I can't seem to be able to do so, though. (Note that Type[] doesn't capture the intended use, since not all arguments need to be the same type.) Is this even possible given the generics that Typescript offers?

about 4 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 Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!