```typescript
/** The factorial of n. */
export function factorial(n: number): number {
  // Throw Error for negative or non-integer argument
  if (n < 0 || !Number.isInteger(n)) {
    throw new Error("Factorial is not defined for negative numbers or non-integers.");
  }

  // Base case: factorial(0) is 1
  if (n === 0) {
    return 1;
  }

  // Recursive case
  return n * factorial(n - 1);
}
```