Skip to content

Suggestion: add @optionalTypeArgs to MapEntry for always_specify_types #55709

Open

Description

@nate-thegrate

Pattern-matching with MapEntry is very satisfying, but when always_specify_types is on, it's kinda awful.

final List<String> list = <String>[
  for (final MapEntry<KeyClass, ValueClassWithAVeryLongName>(:KeyClass key, :ValueClassWithAVeryLongName value) in map.entries)
    '$key, $value',
];

I'd much prefer not needing to add the type parameters here:

final List<String> list = <String>[
  for (final MapEntry(:KeyClass key, :ValueClassWithAVeryLongName value) in map.entries)
    '$key, $value',
];

Activity

  1. lrhn commented on May 14, 2024

    @lrhn
    Member

    I think the lint is probably working as intended.

    Requiring a type annotation for var x = 10;, where the inferred type is obvious, means that the lint really intends all types to be written, even if they are inferred.

    I don't know if it's the same lint that requires the the type parameters to MapEntry. I'd have assumed that

       for (final MapEntry(:KeyClass key, :ValueClassWithAVeryLongName value)  ...

    would be enough, since this lint is about the variable declarations. (And MapEntry is not a raw type here, so should not be affected by strict_raw_types.)

  2. nate-thegrate commented on May 14, 2024

    @nate-thegrate
    Author

    always_specify_types

    It looks like the always_specify_type lint kicks in when you don't add the MapEntry type parameters. (I'll update the original comment for clarity.)

  3. added
    devexp-linterIssues with the analyzer's support for the linter package
    P2A bug or feature request we're likely to work on
    devexp-pkg-metaIssues related to package:meta
    on May 15, 2024
  4. added
    area-devexpFor issues related to the analysis server, IDE support, linter, `dart fix`, and diagnostic messages.
    and removed on Feb 21, 2025
  5. changed the title [-]Suggestion: add `@optionalTypeArgs` to `MapEntry`[/-] [+]Suggestion: add `@optionalTypeArgs` to `MapEntry` for `always_specify_types`[/+] on May 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2A bug or feature request we're likely to work onarea-devexpFor issues related to the analysis server, IDE support, linter, `dart fix`, and diagnostic messages.devexp-linterIssues with the analyzer's support for the linter packagedevexp-pkg-metaIssues related to package:metatype-enhancementA request for a change that isn't a bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions