Question · JavaScript and TypeScript course · Module 7: Advanced TypeScript
Generics vs Union Types
When is it better to use a generic <T> instead of a union type (string | number)?
Answer options
- When the parameter type must be preserved in the return type
- When we need exactly two types
- When we want better runtime performance
- When working only with arrays
You can check the correct answer by solving this task in the CodeWorlds game.