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

176
Visualizações
use a function to execute another function (with a variable amount of parameters) Typescript

Im trying to create a function that can repeat another function with variable amount of paramemters. However I am only getting the reference to anonymous arrow function rather than the return value of the function (func) I am trying to pass in. I've tried func(). but that seems

const testFunction1 = (x:number,y:number) => {
    return {x,y}
}
const testFunction2 = (foo:string, bar:string, baz:string) => {
    return {foo, bar, baz}
}

const repeatFunction = (num: number, func: () => unknown) => {

    const returnValues: Array<(unknown)> = []

    for (let i = 0; i < num; i++) {
        returnValues.push(func())
    }

    return returnValues
}
const result = repeatFunction(5, () => testFunction1(4,5))
console.log(result)

Whats really weird is that when I look into the playground this seems to be working fine. But when I use my editor and debugger I get the following error

Error Uncaught TypeError: func is not a function

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

Most likely you are not passing this function () => testFunction1(4,5) screen

about 4 years ago · Juan Pablo Isaza 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