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

  let result = "";
  let i = 0;

  while (i < template.length) {
    if (template[i] === "{") {
      let j = i + 1;
      while (j < template.length && template[j] !== "}") {
        j++;
      }
      if (j === template.length) {
        throw new Error("Unterminated placeholder");
      }
      const placeholder = template.slice(i + 1, j);
      if (placeholder === "") {
        throw new Error("Empty placeholder name");
      }
      if (!/^[a-zA-Z0-9_]+$/.test(placeholder)) {
        throw new Error("Malformed placeholder name");
      }
      if (!values.hasOwnProperty(placeholder)) {
        throw new Error(`Unknown placeholder: ${placeholder}`);
      }
      result += values[placeholder];
      i = j + 1;
    } else {
      result += template[i];
      i++;
    }
  }

  return result;
}
```