[英]How can I specify type annotations in Dart with `combineReducers`?
我在List
收到來自 linter 的消息:
指定類型注釋
但是我不明白它想要什么類型。 對於Map
我可以這樣:
<String, String>{}
我的Map
在最后的位置,我在開頭指定了類型,但是我找不到適合我的減速器和史詩的正確類型。
我目前的代碼:
final profileReducer = combineReducers<Profile>([
TypedReducer<Profile, UpdateProfileBalanceAction>(_updateProfileBalance),
TypedReducer<Profile, FetchProfileResultAction>(_setProfile),
]);
和:
final epics = combineEpics<AppState>([
TypedEpic<AppState, FetchProfileAction>(profileEpic),
]);
我需要使用的正確類型是:
final Function profileReducer = combineReducers<Profile>(
<Profile Function(Profile, dynamic)>[
TypedReducer<Profile, FetchProfileResultAction>(_setProfile),
]);
但是為了使它更有用,我創建了一個類型:
import 'package:utgard/store/models/profile.dart';
typedef ProfileReducers = Profile Function(Profile, dynamic);
然后我可以在我的減速器中使用,如下所示:
final Function profileReducer = combineReducers<Profile>(<ProfileReducers>[
TypedReducer<Profile, FetchProfileResultAction>(_setProfile),
]);
Dart 不支持聯合類型,因此無法正確鍵入操作.. 將需要“不太現實的類型”
您可以執行以下操作:
final profileReducer = combineReducers<Profile>(<TypedReducer<Profile, Action>>[
TypedReducer<Profile, UpdateProfileBalanceAction>(_updateProfileBalance),
TypedReducer<Profile, FetchProfileResultAction>(_setProfile),
]);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.