Create a TypeScript function that calculates the factorial of a given number n recursively and returns the result.
PLAINFORMAT
// This function calculates the factorial of a given number n recursively
function factorial(n: number): number {
  if (n === 0) {
    return 1;
  } else {
    return n * factorial(n - 1);
  }
}