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

120
Views
Typescript Wrap Overloaded Function Generically with Optional Parameters

I am trying to wrap an overloaded function (from a package I did not write, so I cannot edit the overload declarations) and retain the original parameters and return types of the function. Typescript seems to only pick up the last declared overload function when deciding how to type the wrapper.

Does anyone know of a way to generically wrap an overloaded function and retain typings of all overloads? It would be nice if we could have a Partial<Tuple>

TypeScript Playground link

function wrap<T extends (...args: any[]) => any>(
  fn: T,
  wrapper: (fn: T, ...args: Parameters<T>) => ReturnType<T>
) {
  return (...args: Parameters<T>) => wrapper(fn, ...args)
}

declare function echo(text: string): void
declare function echo(text: string, options: {}): void

const echoWrapped = wrap(echo, (fn, text) => {
  return fn(text)
})

echoWrapped('hello') // error TS2554: Expected 2 arguments, but got 1.
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!