Improve typedef
Usability for Named Tuple-like Structures in Dart
#59607
Labels
area-language
Dart language related items (some items might be better tracked at github.com/dart-lang/language).
type-enhancement
A request for a change that isn't a bug
When using typedef for defining tuple-like structures, the behavior feels unintuitive and error-prone. For example, in the code below:
The FeedbackData fields (message and color) must be accessed using . $1 and . $2. This feels strange, non-descriptive, and introduces potential errors due to lack of clarity.
Current Workaround:
I can rewrite the typedef like this:
However, this approach makes creation tedious because I need to explicitly name every parameter when creating a FeedbackData object.
Suggestion:
Can the following behavior be supported for typedef?
Here, FeedbackData would behave like a named tuple, allowing both intuitive field access (feedbackData.message and feedbackData.color) and concise creation syntax.
Why This Matters:
The current behavior of typedef makes tuple-like constructs harder to use in a way that is both expressive and practical. Enhancing typedef usability for named field access would make writing cleaner, safer, and more readable code easier.
The text was updated successfully, but these errors were encountered: