```ts
export function parseConfig(text: string): Record<string, string> {
  const config: Record<string, string> = {};
  for (const line of text.split("\n")) {
    if (!line.trim()) continue; // Skip blank lines
    if (/^#/.test(line)) continue; // Skip commented lines

    const [key, value] = line.split("=", 2);
    if (!key) throw new Error(`Invalid config file: empty key at line ${text.indexOf('\n', text.lastIndexOf('\n') + 1)}`); // Check for empty key
    if (config[key]) delete config[key]; // Override previous occurrence

    const trimmedKey = key.trim();
    const trimmedValue = value ? value.trim() : "";
    config[trimmedKey] = trimmedValue;
  }
  return config;
}
```