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

195
Views
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 answers
Answer question

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 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!