Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

289
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda