Q51. What are common causes of overusing generics?

Generics become counterproductive when they add type parameters without preserving a meaningful relationship, make inference difficult, or expose implementation complexity to callers. Prefer the simplest contract that accurately models the domain. A generic should enable reuse or precision that a concrete type cannot provide as clearly.

A helper that only ever handles one domain type may be easier to read as a concrete function instead of a generic abstraction.

Note

Interview approach: define the concept, explain why it matters, then mention one trade-off or limitation.

TypeScript concept
// Illustrative TypeScript contract
type Identifier = string;
const id: Identifier = "item-1";
💡 The example demonstrates the compile-time contract discussed in this question.
Key Takeaways
  • Explain the concept in your own words.
  • Know the practical trade-off and its limits.
  • Use a small example to demonstrate the idea.
Knowledge Check

When should a generic be introduced?