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

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

  return result;
}
```