You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
How to satisfy a union of responses into the status function without 1. having to do an if-else/switch and 2. sacrificing type-safety?
I'm trying to utilize neverthrow, which handles Ok 200 and other Errors like 404, 500 into a union. I found out that to the status function is really strict about sending in a union type and would not resolve.
Sometimes, there are 5+ errors that are returned from the query and we don't want to write status for every cases of error into a switch case because we've intentionally return those in the service and they aggregated up to the controller.
Is there a utility, function, or a hack that I can use to resolve this issue like in the example below?
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
How to satisfy a union of responses into the status function without 1. having to do an if-else/switch and 2. sacrificing type-safety?
I'm trying to utilize neverthrow, which handles Ok 200 and other Errors like 404, 500 into a union. I found out that to the
status
function is really strict about sending in a union type and would not resolve.Sometimes, there are 5+ errors that are returned from the query and we don't want to write
status
for every cases of error into a switch case because we've intentionally return those in the service and they aggregated up to the controller.Is there a utility, function, or a hack that I can use to resolve this issue like in the example below?
Example
Typescript Error
Beta Was this translation helpful? Give feedback.
All reactions