```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")) {
    // Trim leading/trailing whitespace, split on the first '='
    const [key, value] = line.trim().split(/=([^=]+)=/, 2);
    if (!key || !value) {
      throw new Error(`Invalid config line: ${line}`);
    }
    // Remove any leading '#' and trim whitespace around key/value
    key = key.replace(/^#+|#.+$/g, '').trim();
    value = value.trim();
    config[key] = value;
  }
  return config;
}
```