Skip to content

typedef isn't allowed in statement blocks #3200

Closed
@Hixie

Description

@Hixie

I like to be explicit about types everywhere and not rely on inference.

I wish I could do something like the following, where I use a typedef to avoid having to duplicate a record's type, without the typedef having to be far away from the one code block where I use it:

    ...
    case 'create-new-triage-labels':
      if (arguments.length != 1) {
        print('Usage: dart run github_tools create-new-triage-labels');
        exit(1);
      }
      typedef LabelDescription = ({String name, String color, String description});
      final List<LabelDescription> newLabels = <LabelDescription>[];
      for (final String team in teams.keys) {
        if (team != 'ecosystem' && team != 'infra' && team != 'release' && team != 'google-testing' && team != 'news' && team != 'codelabs') {
          newLabels.add((name: 'team-$team', description: 'Owned by ${teams[team]}', color: '198022'));
        }
        newLabels.add((name: 'triaged-$team', description: 'Triaged by ${teams[team]}', color: 'b8ccba'));
        newLabels.add((name: 'fyi-$team', description: 'For the attention of ${teams[team]}', color: '29cc36'));
      }
      for (final LabelDescription label in newLabels) {
        await engine.createLabel(label.name, label.color, label.description);
      }
    ...

Metadata

Metadata

Assignees

No one assigned

    Labels

    requestRequests to resolve a particular developer problem

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions