Hypothetical question: What happens if you add a new genre and you don’t want the default banner to be returned?
What I’m getting at is that it’s much safer to throw in a default. Or if it’s typescript it’s safer to return a never type. That way you can exhaustively consider enum values or any union of types. I describe that technique here.
Good point, for sure a switch statement should have a default.
I didn't include it in this case for brevity, and this is just an example. For something slightly more evolved I would actually resort to the factory pattern to create my return types and simplify the creation logic even more
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Hypothetical question: What happens if you add a new genre and you don’t want the default banner to be returned?
What I’m getting at is that it’s much safer to throw in a default. Or if it’s typescript it’s safer to return a
never
type. That way you can exhaustively consider enum values or any union of types. I describe that technique here.Good point, for sure a switch statement should have a default.
I didn't include it in this case for brevity, and this is just an example. For something slightly more evolved I would actually resort to the factory pattern to create my return types and simplify the creation logic even more