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
{{ message }}
Show optional union field names in intellisense #13682
I take advantage of the fact that union fields may optionally be named within each case of a union type, just for readability. I think this is a great feature, as it may not always be obvious just from the type what the field data means. I just learned that these names can actually be used when pattern matching. Here's the example DU taken from the language specification:
type Shape =
| Rectangle of width: float * length: float
| Circle of radius: float
| Prism of width: float * float * height: float
So, I can construct a Circle with either
let circle = Circle 1.0
which of course is probably fine for this simple example, but if I prefer to use the field name for increased readablity:
let circle = Circle (radius = 1.0)
The only little hangup with the latter is that the name "radius" does not appear in Intellisense, so I have to remember what name I gave the field. Is this possibly an oversight?
I was just playing with this again and realized that if hover the mouse over the constructor, I see the union field names. So, the addition to intellisense would be nice just for the sake of autocompletion. But FWIW, I would consider my suggestion to be a pretty low priority.
Activity
jimfoye commentedon Aug 14, 2022
I was just playing with this again and realized that if hover the mouse over the constructor, I see the union field names. So, the addition to intellisense would be nice just for the sake of autocompletion. But FWIW, I would consider my suggestion to be a pretty low priority.