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

  const stack: { placeholderName: string, index: number }[] = [];
  let result = '';

  for (let i = 0; i < template.length; i++) {
    const char = template[i];

    if (char === '{') {
      stack.push({ placeholderName: '', index: i });
    } else if (char === '}') {
      if (stack.length === 0) {
        throw new Error('Unterminated placeholder');
      }

      const { placeholderName, index } = stack.pop()!;
      const value = values[placeholderName];

      if (!value) {
        throw new Error(`Unknown placeholder: ${placeholderName}`);
      }

      result += template.slice(index, i);
      result += value;
    } else {
      result += char;
    }
  }

  return result;
}
```