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

103
Views
Given an overloaded function and parameter types, find the return type in Typescript?

According to this answer (https://stackoverflow.com/a/52761156/599184), ReturnType<> doesn't work with overloaded functions in general. However, would it be possible to select a particular version of the overloaded function and get its return type?

The only way I can think of is to have code invoking the overloaded function.

function fn(arg: string): string;

function fn(arg: number): number;

function fn(arg: string | number): string | number {
    return arg;
}

const temp1 = () => fn('string');
type Type1 = ReturnType<typeof temp1>; // string

const temp2 = () => fn(123);
type Type2 = ReturnType<typeof temp2>; // number

TS Playground

Is there a cleaner way where I don't have to pass in the arguments (just the argument type)?

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!