```ts

/** Parses KEY=VALUE pairs from a config file into a Record<string, string>. */
export function parseConfig(text: string): Record<string, string> {
  const config: Record<string, string> = {};
  for (const line of text.split("\n")) {
    // Trim leading and trailing whitespace
    let trimmedLine = line.trim();
    
    // Ignore empty lines or comments starting with #
    if (!trimmedLine || trimmedLine.startsWith("#")) {
      continue;
    }
    
    // Split the line on the first =
    const parts = trimmedLine.split("=", 2);
    if (parts.length !== 2) {
      throw new Error(`Line without an '=': ${trimmedLine}`);
    }
    
    const [key, value] = parts;
    
    // Check for keys starting with __proto__
    if (key.startsWith("__proto__")) { 
      config[key.replace(/^__proto__\=/, "")] = value; 
      continue;
    }
    
    // Trim whitespace around the key and value
    const normalizedKey = key.trim();
    const normalizedValue = value.trim();
    
    // Add to config object
    config[normalizedKey] = normalizedValue;
  }
  return config;
}
```