QuestionTypeScript Deep Dive
When do generics actually pay off?
Lucas Moreau
Posted 5 days ago
I understand the syntax, but in my own code I never know when a generic is worth it versus a union or just `unknown`. Any rules of thumb?
Lucas Moreau
Posted 5 days ago
I understand the syntax, but in my own code I never know when a generic is worth it versus a union or just `unknown`. Any rules of thumb?
Use a generic when the output type depends on the input type. If a function returns the same thing whatever you pass in, you don't need one.
Showing 4 of 18 · sorted by oldest