I’m mystified why the following Dart code generates a runtime error:
class Store<ID, T> {
Store({Map<ID, T> values = const {}}) : _cache = values;
final Map<ID, T> _cache;
void put(ID id, T value) {
_cache[id] = value;
}
}
...
final foo = Store<int, Store<int, String>>();
// Error: TypeError: 7: type 'int' is not a subtype of type 'Never'
foo.put(7, Store<int, String>());
This isn’t an issue if I use a Map
directly like this:
final foo = Map<int, Map<int, String>>();
foo[7] = Map<int, String>());
Is there something about Dart generics I need to understand to make Store
work?