[英]How can I specify type annotations in Dart with `combineReducers`?
I receive a message at the List
from linter saying:我在List
收到来自 linter 的消息:
Specify type annotations指定类型注释
However I can't understand what type it wants.但是我不明白它想要什么类型。 For Map
I could get like so:对于Map
我可以这样:
<String, String>{}
Where my Map
is at the end, and I specify the type at the beginning, but I can't find the correct type for my reducer and my epics.我的Map
在最后的位置,我在开头指定了类型,但是我找不到适合我的减速器和史诗的正确类型。
My current code:我目前的代码:
final profileReducer = combineReducers<Profile>([
TypedReducer<Profile, UpdateProfileBalanceAction>(_updateProfileBalance),
TypedReducer<Profile, FetchProfileResultAction>(_setProfile),
]);
and:和:
final epics = combineEpics<AppState>([
TypedEpic<AppState, FetchProfileAction>(profileEpic),
]);
The correct type I needed to use was:我需要使用的正确类型是:
final Function profileReducer = combineReducers<Profile>(
<Profile Function(Profile, dynamic)>[
TypedReducer<Profile, FetchProfileResultAction>(_setProfile),
]);
But to make that more usable, I created a type:但是为了使它更有用,我创建了一个类型:
import 'package:utgard/store/models/profile.dart';
typedef ProfileReducers = Profile Function(Profile, dynamic);
Then I can use in my reducers, like so:然后我可以在我的减速器中使用,如下所示:
final Function profileReducer = combineReducers<Profile>(<ProfileReducers>[
TypedReducer<Profile, FetchProfileResultAction>(_setProfile),
]);
Dart doesn't support union type so typing actions properly won't be possible.. A "less realistic type" will be required Dart 不支持联合类型,因此无法正确键入操作.. 将需要“不太现实的类型”
You can do the following:您可以执行以下操作:
final profileReducer = combineReducers<Profile>(<TypedReducer<Profile, Action>>[
TypedReducer<Profile, UpdateProfileBalanceAction>(_updateProfileBalance),
TypedReducer<Profile, FetchProfileResultAction>(_setProfile),
]);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.