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
We currently fetch data and explicitly type the response, validating only on the domain layer. Whilst the layer separation makes sense, we can't be 100% sure that the type matches the response until after validation. Ideally, we should assume the response is unknown until validated.
We should either adjust the types of requests, or validate the response immediately.
Requirements
There are a couple ways to approach this, each adjusting the architecture of the project:
Change reponse types to unknown (or something like T | unknown).
The downside of the above is that the types are "lost" and it is hard to then find the corresponding type. A better suggestion would setting all requests as T | unknown. This is then a) easier as the generic of the service can be changed and not that of every request and b) we always have the relevant type "in place". Validating the response of this will then "remove" then unknown from the union.
Immediately validate responses.
We could "hoist" the validation to the datasource layer. If we want to remain "strict", this does not fit our mental model. However, it means that every call returns the expected type but we generally inject the respective repository though. One thing to note is that we are doing something similar with the "incoming data" of DTOs.
Additional information
No response
The text was updated successfully, but these errors were encountered:
Description
We currently fetch data and explicitly type the response, validating only on the domain layer. Whilst the layer separation makes sense, we can't be 100% sure that the type matches the response until after validation. Ideally, we should assume the response is
unknown
until validated.We should either adjust the types of requests, or validate the response immediately.
Requirements
There are a couple ways to approach this, each adjusting the architecture of the project:
unknown
(or something likeT | unknown
).The downside of the above is that the types are "lost" and it is hard to then find the corresponding type. A better suggestion would setting all requests as
T | unknown
. This is then a) easier as the generic of the service can be changed and not that of every request and b) we always have the relevant type "in place". Validating the response of this will then "remove" thenunknown
from the union.We could "hoist" the validation to the datasource layer. If we want to remain "strict", this does not fit our mental model. However, it means that every call returns the expected type but we generally inject the respective repository though. One thing to note is that we are doing something similar with the "incoming data" of DTOs.
Additional information
No response
The text was updated successfully, but these errors were encountered: