```ts
/**
 * Computes the Levenshtein (edit) distance between two strings.
 * @param a - The first string.
 * @param b - The second string.
 * @returns The minimum number of single-character insertions, deletions, and substitutions needed to transform `a` into `b`.
 * @throws Error if either argument is not a string.
 */
export function editDistance(a: string, b: string): number {
  if (typeof a !== 'string' || typeof b !== 'string') {
    throw new Error('Both arguments must be strings.');
  }

  const m = a.length;
  const n = b.length;

  // Create a DP table with (m+1) rows and (n+1) columns
  const dp: number[][] = Array.from({ length: m + 1 }, () => Array(n + 1).fill(0));

  // Initialize base cases
  for (let i = 0; i <= m; i++) {
    dp[i][0] = i; // Cost of deleting all characters from a
  }
  for (let j = 0; j <= n; j++) {
    dp[0][j] = j; // Cost of inserting all characters into a
  }

  // Fill the DP table
  for (let i = 1; i <= m; i++) {
    for (let j = 1; j <= n; j++) {
      if (a[i - 1] === b[j - 1]) {
        dp[i][j] = dp[i - 1][j - 1]; // No operation needed
      } else {
        const insertCost = dp[i][j - 1] + 1;   // Insert character into a
        const deleteCost = dp[i - 1][j] + 1;   // Delete character from a
        const replaceCost = dp[i - 1][j - 1] + 1; // Replace character in a
        dp[i][j] = Math.min(insertCost, deleteCost, replaceCost);
      }
    }
  }

  return dp[m][n];
}
```