```ts
/**
 * Parses a config file into a key-value object.
 * @param text - The contents of the config file as a string.
 * @returns A Record with keys and values from the config file.
 */
export function parseConfig(text: string): Record<string, string> {
  const config: Record<string, string> = {};
  let lineNumber = 0;

  for (const line of text.split("\n")) {
    lineNumber++;
    const trimmedLine = line.trim();

    // Ignore blank lines and lines starting with #
    if (!trimmedLine || trimmedLine.startsWith("#")) {
      continue;
    }

    const firstEqualsIndex = trimmedLine.indexOf("=");
    if (firstEqualsIndex === -1) {
      throw new Error(`Invalid line ${lineNumber}: no '=' found`);
    }

    const key = trimmedLine.slice(0, firstEqualsIndex).trim();
    const value = trimmedLine.slice(firstEqualsIndex + 1).trim();

    if (!key) {
      throw new Error(`Invalid line ${lineNumber}: empty key`);
    }

    // Ensure keys do not reach Object.prototype
    config[Symbol.toStringTag] = key;
    config[key] = value;
  }

  return config;
}
```