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
I sometimes want to use the return type of an Effect function but do not have direct access to the type.
Reading Effect source is sometimes made more difficult due to the complex types, especially when the return types are duplicated for dual functions.
What is the feature you are proposing to solve the problem?
I propose that the return types be refactored out of the definition so that they can be easily re-used.
For example, the current Struct.pick is defined by:
This has the added bonus of making the source easier to read by reducing the complexity of the type definition and assigning human readable names.
What alternatives have you considered?
Copy & paste the type
a. This would be noisy which reduces readability.
b. It is error-prone.
c. It is likely to become out-of-sync.
d. Sometimes the return types use other helper types that are also not exported, further complicating the process.
Use ReturnType<typeof Struct.pick<typeof myStruct, typeof pickKeys>
a. This is also noisy, reducing readability.
b. ReturnType relies on type inference through conditional types, which is not as reliable (or performant) as direct type declarations.
The text was updated successfully, but these errors were encountered:
I don"t think that this is practical. It is also not possible in many cases (e.g. for overloaded function declarations) in a way that would keep the perceived simplicity / readability benefits. Personally, I also don"t find it more readable. This is more a matter of taste / personal opinion, but I find that it adds an additional indirection where one has to jump back and forth to fully ready the type declaration.
Could you maybe elaborate what your concrete use-case is? I"ve personally not really had this need except for a few rare cases maybe.
What is the problem this feature would solve?
What is the feature you are proposing to solve the problem?
I propose that the return types be refactored out of the definition so that they can be easily re-used.
For example, the current
Struct.pick
is defined by:But it would be helpful to be re-defined as:
This has the added bonus of making the source easier to read by reducing the complexity of the type definition and assigning human readable names.
What alternatives have you considered?
Copy & paste the type
a. This would be noisy which reduces readability.
b. It is error-prone.
c. It is likely to become out-of-sync.
d. Sometimes the return types use other helper types that are also not exported, further complicating the process.
Use
ReturnType<typeof Struct.pick<typeof myStruct, typeof pickKeys>
a. This is also noisy, reducing readability.
b.
ReturnType
relies on type inference through conditional types, which is not as reliable (or performant) as direct type declarations.The text was updated successfully, but these errors were encountered: