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 }}
Repository navigation
Suggestion: add @optionalTypeArgs to MapEntry for always_specify_types #55709
Pattern-matching with MapEntry is very satisfying, but when always_specify_types is on, it's kinda awful.
finalList<String> list =<String>[
for (finalMapEntry<KeyClass, ValueClassWithAVeryLongName>(:KeyClass key, :ValueClassWithAVeryLongName value) in map.entries)
'$key, $value',
];
I'd much prefer not needing to add the type parameters here:
finalList<String> list =<String>[
for (finalMapEntry(:KeyClass key, :ValueClassWithAVeryLongName value) in map.entries)
'$key, $value',
];
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 (finalMapEntry(: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.)
changed the title [-]Suggestion: add `@optionalTypeArgs` to `MapEntry`[/-][+]Suggestion: add `@optionalTypeArgs` to `MapEntry` for `always_specify_types`[/+]on May 15, 2026
Activity
lrhn commentedon May 14, 2024
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 thatwould be enough, since this lint is about the variable declarations. (And
MapEntryis not a raw type here, so should not be affected bystrict_raw_types.)nate-thegrate commentedon May 14, 2024
It looks like the
always_specify_typelint kicks in when you don't add theMapEntrytype parameters. (I'll update the original comment for clarity.)[-]Suggestion: add `@optionalTypeArgs` to `MapEntry`[/-][+]Suggestion: add `@optionalTypeArgs` to `MapEntry` for `always_specify_types`[/+]