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

  const placeholderRegex = /\{([a-zA-Z0-9_]+)\}/g;
  let match;

  return template.replace(placeholderRegex, (match, name) => {
    if (!name || !/^[a-zA-Z0-9_]+$/.test(name)) {
      throw new Error("Invalid placeholder name: " + name);
    }

    const value = values[name];
    if (value === undefined) {
      throw new Error("Unknown placeholder name: " + name);
    }

    return value;
  });
}
```