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
For particularly complicated type definitions (eg. large, complex unions), I would like to add a way to create locally bound types that are scoped only to that type definition. These would compile away along with the type itself, and are purely to enable local abstractions for legibility and "DRY"ness.
π Motivating Example
As type definitions get more complicated, they tend to become less legible and more difficult to maintain. A significant part of the struggle comes from not having a syntactic tool to create abstractions within the context of the type itself.
π» Use Cases
The sample below is a greatly simplified example of some props definitions I use in a table column type. In the example, we have an item type T, a value type V, and a set of keys which are valid for filtering (F) and sorting (S).
In the "explicit" version, both logic and code are duplicated in the type definition.
In the readable version, I've extracted a "global" helper type to make the overall type a bit more legible. While this does work and makes it more legible, we're forced to copy and paste strings of generic arguments that obscure the intention and risk unnecessary C&P mistakes. Additionally, "global" types need to be named more verbosely to keep clarity maximalized.
The ideal type is my proposal - it improves legibility and discourages copy and paste, instead relying on locally bound type helpers. I don't have a strong opinion about the keyword / syntax to actually enable the feature (I'm using where as inspired by Haskell where expressions), though I do think having the syntax be supported as a postfix to the type definition is significant, as it encourages taking in the type as a whole rather than the component implementations.
Suggestion
π Search Terms
"type internal definition" "where" "where clause" "local variable" "local binding"
β Viability Checklist
My suggestion meets these guidelines:
β Suggestion
For particularly complicated type definitions (eg. large, complex unions), I would like to add a way to create locally bound types that are scoped only to that type definition. These would compile away along with the type itself, and are purely to enable local abstractions for legibility and "DRY"ness.
π Motivating Example
As type definitions get more complicated, they tend to become less legible and more difficult to maintain. A significant part of the struggle comes from not having a syntactic tool to create abstractions within the context of the type itself.
π» Use Cases
The sample below is a greatly simplified example of some props definitions I use in a table column type. In the example, we have an item type T, a value type V, and a set of keys which are valid for filtering (F) and sorting (S).
In the "explicit" version, both logic and code are duplicated in the type definition.
In the readable version, I've extracted a "global" helper type to make the overall type a bit more legible. While this does work and makes it more legible, we're forced to copy and paste strings of generic arguments that obscure the intention and risk unnecessary C&P mistakes. Additionally, "global" types need to be named more verbosely to keep clarity maximalized.
The ideal type is my proposal - it improves legibility and discourages copy and paste, instead relying on locally bound type helpers. I don't have a strong opinion about the keyword / syntax to actually enable the feature (I'm using
where
as inspired by Haskell where expressions), though I do think having the syntax be supported as a postfix to the type definition is significant, as it encourages taking in the type as a whole rather than the component implementations.The text was updated successfully, but these errors were encountered: