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

  let result = '';
  let i = 0;

  while (i < template.length) {
    if (template[i] === '{') {
      const end = template.indexOf('}', i);
      if (end === -1) {
        throw new Error('Unmatched opening brace');
      }
      const placeholder = template.slice(i + 1, end);
      if (!placeholder || /[^a-zA-Z0-9_]/.test(placeholder)) {
        throw new Error('Invalid placeholder name');
      }
      result += values[placeholder] ?? '';
      i = end + 1;
    } else {
      result += template[i];
      i++;
    }
  }

  return result;
}
```