Skip to main content

avoid_types_on_closure_parameters

Details about the 'avoid_types_on_closure_parameters' diagnostic produced by the Dart analyzer.

Unnecessary type annotation on a function expression parameter.

Description

#

The analyzer produces this diagnostic when a parameter of a function expression (closure) has an explicit type annotation, and the closure is in a context where the parameter type can be inferred.

Example

#

The following code produces this diagnostic because the parameter x in the closure passed to l.map has an explicit type annotation of int, which is unnecessary because the type can be inferred from the list's type:

dart
void f(List<int> l) {
  l.map((int x) => x.isEven);
}

Common fixes

#

Remove the type annotation:

dart
void f(List<int> l) {
  l.map((x) => x.isEven);
}