Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add rule to require explicitly naming DU fields #719

Open
nkosi23 opened this issue Feb 23, 2025 · 0 comments
Open

Add rule to require explicitly naming DU fields #719

nkosi23 opened this issue Feb 23, 2025 · 0 comments

Comments

@nkosi23
Copy link

nkosi23 commented Feb 23, 2025

When a discriminated union is defined, for example:

type PaymentMethod = Card of CreditCard

The compiler automatically creates a property named Item for the Card case. The issue is, for situations where we rely heavily on serialization, these automatically generated names are both dangerous and impractical.

In our case, we typically serialize DUs 1) to store a record in the database, and 2) to send the record to the typescript front-end. For this later case in particular, wrapping client-side types in properties named "item", is terrible.

Unfortunately, these situations may be spotted too late if our code does not use some piece of data immediately. And once an automatically generated field name is stored in the production DB, making the change is a much higher cost endeavour.

Thus my proposal to add a rule requiring developers to give explicit name field names to DU cases, such as:

type PaymentMethod = Card of CardDetails: CreditCard
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant