Skip to content
TypeScript·Intermediate·Coding·1 min read

When is a generic type parameter unnecessary?

Short interview answer

If it appears only once and does not connect inputs, outputs, or members, it may add ceremony without information. Use the concrete constraint type or unknown instead. Type parameters should model a real relationship.

Example

TypeScript
// Pointless generic — T is used once, connects nothingfunction log<T>(x: T): void { console.log(x); }// Just: function log(x: unknown): void

Key takeaway

Explain the underlying mental model clearly, then support it with a concrete example and its trade-offs.

← Back to Generics

Related questions