```ts
export function fillTemplate(template: string, values: Record<string, string>): string {
  if (typeof template !== 'string') {
    throw new Error('Template must be a string');
  }

  const placeholders = template.match(/\{([a-zA-Z0-9_]+)\}/g);
  if (!placeholders) return template;

  for (const placeholder of placeholders) {
    const [_, name] = placeholder.split('{').map(s => s.trim());
    if (!name || !/^[a-zA-Z0-9_]+$/.test(name)) {
      throw new Error(`Invalid placeholder: ${placeholder}`);
    }
    if (!(name in values)) {
      throw new Error(`Missing value for placeholder: ${placeholder}`);
    }

    template = template.replace(placeholder, values[name]);
  }

  return template;
}
```