Hi!
Recently, some co-workers and I have been discussing a use case which involves React and TypeScript.
We are working on an app related to logistics, and in this app, we have an entity called Order. Among many other properties, an order has a property called status. This status property can be one of four different strings: pending, invoiced, created, and closed. These statuses are defined in an Enum on the backend (It doesn't matter, but the backend is written in PHP with Symfony).
This means that the backend will always return one of these four known statuses, not random strings.
Okay, knowing this, on the front-end, with React and TypeScript, I created a type called OrderStatus with the four possible statuses, something like this:
type OrderStatus = 'pending' | 'invoiced' | 'created' | 'closed'
export default OrderStatus
At this point, the discussion starts from the fact that my colleagues are not happy with me re-defining the types on the front-end. Their argument is that if we change a status name on the backend, we'll have to change the status also on the front-end, claiming that this is redundant.
I have to say, that my colleagues have no experience working with TypeScript; they are more focused on the backend, especially in PHP and Symfony.
From my point of view, it is really important to have these things typed because if the possible statuses are already defined on the backend, it means that they are consistent. Knowing what kind of value the backend can return to you could be really useful when performing certain actions based on the type of the status. Just imagine that I have to show or not show a button based on the status type, for example, when the order is pending.
I would like to read your thoughts about this, and if I am right, what argument would you give to my colleagues, because it seems that they are not understanding my point. If I am not right, I would like to know your opinion as well.
Thanks in advance!