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

281
Views
Estoy dando el tipo genérico al parámetro de la función, cuando llamo a la función me da un error

Estoy dando el tipo genérico al parámetro de la función, cuando llamo a la función me da un error "Esta expresión no se puede llamar. El tipo desconocido no tiene firma de llamada"

 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

Como está escrito en esta respuesta https://stackoverflow.com/a/62233415/3262937 , debe usar T extends Function para que el compilador de TypeScript sepa que su parámetro genérico es una función.

Vea este patio de recreo: https://www.typescriptlang.org/play?#code/GYVwdgxgLglg9mABAQwBQEpEG9ECcCmUIuSA5MgEYSmIC+AUPaJLAoswDwAqi+AHlHxgAJgGdEAMXDR4YAHyo+ALkRcANIgCeK0VFwwwAc0xZ6icxfMEiJRHwyIA1FoDcZiwybUyD9QwybUyD9QwybUyD9Q

about 4 years ago · Santiago Gelvez Report

0

Ahí está la solución.

 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!