fluttercommunity / redux.dart

Redux for Dart
https://pub.dev/packages/redux
MIT License
519 stars 61 forks source link

TypedReducer: A value of type '(dart.core::bool, dynamic) → dart.core::bool' can't be assigned to a variable of type '(dynamic, dynamic) → dynamic' #24

Closed AxelMarquez closed 6 years ago

AxelMarquez commented 6 years ago

After upgrading my project to flutter-redux: 0.5.0 and dart-redux: 3.0.0 I’m having this issue. The code rising the error is:

final hasInternetReducer = combineReducers([
  TypedReducer<bool, LostInternetAction>((bool state, LostInternetAction action) => false),
  TypedReducer<bool, RecoveredInternetAction>((bool state, RecoveredInternetAction action) => true),
]);

The complete error is:

lib/redux/reducer.dart:83:7: Error: A value of type '(dart.core::bool, dynamic) → dart.core::bool' can't be assigned to a variable of type '(dynamic, dynamic) → dynamic'.
Try changing the type of the left hand side, or casting the right hand side to '(dynamic, dynamic) → dynamic'.

I'm using dart 2 with flutter v0.2.7-pre.1 No issues found by flutter doctor

brianegan commented 6 years ago

Hey @AxelMarquez, wow, that's a crazy message haha. In any case, it's basically saying you need to provide a bit more type information to combineReducers, e.g. combineReducers<bool>:

final hasInternetReducer = combineReducers<bool>([
  TypedReducer<bool, LostInternetAction>((bool state, LostInternetAction action) => false),
  TypedReducer<bool, RecoveredInternetAction>((bool state, RecoveredInternetAction action) => true),
]);
AxelMarquez commented 6 years ago

You're right! I thought flutter's type inference would catch that, sadly it didn't :( Many thanks for the help

brianegan commented 6 years ago

Yah, it's been a little rough in that regard... I don't think the IDE warnings have caught up with the language implementation, so I've noticed a lot of runtime errors as well