To me match feels more declarative, we aren't checking the internal representation of the RemoteData value, only providing handlers for all the cases. And since it is function call, it is an expression, wheres switch is a statement.
Eg. going from this to using switch would require quite some boilerplate code.
It's true that TypeScript can do exhaustiveness check on the switch statement. But that requires either to add a default case with a never assertion, or to be in a context where we have to return something in all the branches.
Eg. in a case like this, the switch would produce no error but the match would.
To me
match
feels more declarative, we aren't checking the internal representation of the RemoteData value, only providing handlers for all the cases. And since it is function call, it is an expression, wheresswitch
is a statement.Eg. going from this to using
switch
would require quite some boilerplate code.It's true that TypeScript can do exhaustiveness check on the
switch
statement. But that requires either to add adefault
case with a never assertion, or to be in a context where we have to return something in all the branches.Eg. in a case like this, the
switch
would produce no error but thematch
would.Ultimately, I think it's a matter of personal preference, based on what are the priorities and what the team feels more comfortable with.