Dart strong mode: error on anonymous return function

I am getting the following error. The argument type 'dynamic' can't be assigned to the parameter type '() -> dynamic'

Example:

outerFunc(somevar) {
    return () {....} 
}
anOtherFunction(func()) {....}

anOtherFunction(outerFunc('test'));

      

This happens when I return an anonymous function in strong mode using the analysis_options.yaml parameter.

strong-mode:
  implicit-casts: false

      

+3


source to share


1 answer


outerFunc

does not specify a return type, so it is assumed dynamic

. You can create a typedef and use it as the return type for outerFunc

. The type of the function cannot be inferred from the return statement.

typedef dynamic F();

F outerFunc(somevar) {
  return () {};
}

      



You can also write the function type in the line

dynamic Function() outerFunc(somevar) {
  return () {};
}

      

+1


source







All Articles