rest_element_in_map_pattern
A map pattern can't contain a rest pattern.
Description
#The analyzer produces this diagnostic when a map pattern contains a rest pattern. Map patterns match a map with more keys than those explicitly given in the pattern (as long as the given keys match), so a rest pattern is unnecessary.
Example
#The following code produces this diagnostic because the map pattern contains a rest pattern:
dart
void f(Map<int, String> x) {
if (x case {0: _, ...}) {}
}
Common fixes
#Remove the rest pattern:
dart
void f(Map<int, String> x) {
if (x case {0: _}) {}
}
Was this page's content helpful?
Thank you for your feedback!
Provide details Thank you for your feedback! Please let us know what we can do to improve.
Provide details Unless stated otherwise, the documentation on this site reflects Dart 3.8.1. Page last updated on 2025-05-08. View source or report an issue.