Which response type should wrapException have? #67
Replies: 2 comments 1 reply
-
I'd rather to stick with the object approach because with the tuple approach makes hard to follow a flow when it comes with 2+ wrappers, as the names are likely to be very similar. Also, Javascript engineers are quite used to work with objects so it shouldn't be hard to follow the new interface. Regarding the attributes names, I'd go with I'm just not sure about the |
Beta Was this translation helpful? Give feedback.
-
Then object it is! Implemented here #30 |
Beta Was this translation helpful? Give feedback.
-
Current scenario
Currently we return a tuple of two positions:
This has some limitations, as also described here:
#8 and #29
In short, TS is unable to determine if the response the consumer got was an error or a success in a easy/well typed way.
That is because
unknown
is the strongest type and removes theundefined
definition.This has forced consumers to create utility functions like the one here: #8
Possible solutions
Tuple with extra parameter
You can use this Typescript playground to check: TS Playground tuple
The definition would be something like:
Consuming this would be something like:
Pros
Cons
Object response
You can use this Typescript playground to check: TS Playground object response
The definition would be something like:
Consuming this would be something like:
Pros
isError
by setting thedata
to unknown otherwise.Cons
isError
.To be defined:
Attribute names
or
Which is best? Other options?
Beta Was this translation helpful? Give feedback.
All reactions