```typescript
import type { Record } from "typescript";

/** The KEY=VALUE pairs of a config file. */
export function parseConfig(text: string): Record<string, string> {
  const config: Record<string, string> = {};
  for (const line of text.split("\n")) {
    const trimmedLine = line.trim();
    if (!trimmedLine || trimmedLine.startsWith("#")) continue;
    
    const [key, value] = trimmedLine.split("=", 2) as [string, string];
    if (!key) throw new Error(`Invalid config: empty key on line ${lineNumber}`);
    
    config[key] = value ?? "";
  }
  
  return config;

  // Helper function to track line numbers in a more robust way
  function lineNumber(line: string): number {
    let num = 0;
    for (const char of text.slice(0, line.length + 1)) {
      if (/[\n\r]/.test(char)) num++;
    }
    return num;
  }
}
```