```typescript
/** The factorial of n. */
export function factorial(n: number): number {
  if (n < 0 || !Number.isInteger(n)) {
    throw new Error('Negative or non-integer argument');
  }
  // Base case for factorial(0)
  return n === 0 ? 1 : n * factorial(n - 1);
}
```