```ts
function tagsOf(line: unknown): string[] {
  if (!line || typeof line !== 'string') {
    throw new Error('Invalid input');
  }
  return line.split(',').map(tag => tag.trim()).filter(tag => tag);
}

function tagIndex(lines: string[]): Record<string, string[]> {
  const index: Record<string, string[]> = {};
  for (const line of lines) {
    if (!line || typeof line !== 'string') {
      throw new Error('Invalid input');
    }
    const tags = tagsOf(line);
    for (const tag of tags) {
      if (!index[tag]) {
        index[tag] = [];
      }
      index[tag].push(line);
    }
  }
  return index;
}
```