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
Currently now when you have an interface or type that use an union, is really hard to access to the desired property.
In the example below you could see how is not possible to access to a specific property from an union (at least you force the type). However defining generics in the root object and make programmers define the expected union is more much friendly programming experience.
The generation process could be something like:
Check for Unions in the object, generate as many generic as unions in the root object and start from A to Z.
Generate each type of an union separately.
Do conditional type until check all types in the union.
Follow the same process with Unions that have nested Unions.
@adairrr thanks for the suggestion of ts-pattern. I think is really useful in case where you don't know what data is coming. In scenarios where you already know what is going to come, it would be really useful to have something like what I proposed.
I think is very annoying have to force the definition of an union type every time you want to interact with that interface.
Given the example below I would have to do something like this:
assuming that method has a return type of ProposalInterface<ExpirationNever> I never would have to cast or to force a type. In the case above is not that annoying because ExpirationNever is a small interface but there are much bigger interfaces and having to define them is repetitive.
Currently now when you have an interface or type that use an union, is really hard to access to the desired property.
In the example below you could see how is not possible to access to a specific property from an union (at least you force the type). However defining generics in the root object and make programmers define the expected union is more much friendly programming experience.
The generation process could be something like:
Follow the same process with Unions that have nested Unions.
You could find a full example here: https://gist.github.com/j0nl1/22dde0ef0bfaf1c0bea870a0a39e039e
The text was updated successfully, but these errors were encountered: