Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

282
Visualizações
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 Respostas
Responde à pergunta

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 Relatório

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda