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

196
Visualizações
getting no-unused-vars for any recursive function?

I've realized that any recursive function will hit no-unused-vars error which I don't understand why

Simple recursion as below

const factorial = (x: number) => {
  if (x === 0) return 1;

  return x * factorial(x - 1);
};

enter image description here

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

0

Here is the thing: if you declare a variable that is not exported (that means it cannot be used outside the file), you will have to use it in the file or export the function. So, you could do either this:

export const factorial = (x: number): number => {
  if (x === 0) return 1;

  return x * factorial(x - 1);
};

or call the function in the file:

const factorial = (x: number): number => {
  if (x === 0) return 1;

  return x * factorial(x - 1);
};

factorial(42);

See here: https://tsplay.dev/w11ekw

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