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

285
Views
I am giving the generic type to the function parameter, when i call the function it gives me an error

I am giving the generic type to the function parameter, when I call the function it gives me an error "This expression is not callable. Type unknown has no call signature"

function a() { return 'abc' }

function fun<T>(x: T, y: string) {
        return x() + y;
    }

fun(a, "str")
about 4 years ago · Santiago Gelvez
2 answers
Answer question

0

As written in this answer https://stackoverflow.com/a/62233415/3262937 you should use T extends Function so that the Typescript compiler knows that you generic parameter is a Function.

See this playground: https://www.typescriptlang.org/play?#code/GYVwdgxgLglg9mABAQwBQEpEG9ECcCmUIuSA5MgEYSmIC+AUPaJLAoswDwAqi+AHlHxgAJgGdEAMXDR4YAHyo+ALkRcANIgCeK0VFwwwAc0xZ6icxfMEiJRHwyIA1FoDcZiwybhUyDQCJdXD90IA

about 4 years ago · Santiago Gelvez Report

0

There is the solution.

function a() { return 'abc' }

function fun<T>(x: T, y: string) {
        return x + y;
    }

fun(a(), "str");
about 4 years ago · Santiago Gelvez 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!