gpt4 book ai didi

dart - 如何在 Dart 中使用 `combineReducers` 指定类型注释?

转载 作者:IT王子 更新时间:2023-10-29 06:58:28 26 4
gpt4 key购买 nike

我在 List 收到一条消息来自 linter 说:

Specify type annotations

但是我不明白它想要什么类型。对于 Map我可以这样:

<String, String>{}

我的Map在哪里在最后,我在开头指定了类型,但是我找不到适合我的 reducer 和我的 epics 的正确类型。

我当前的代码:

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);

然后我可以在我的 reducer 中使用,像这样:

final Function profileReducer = combineReducers<Profile>(<ProfileReducers>[
TypedReducer<Profile, FetchProfileResultAction>(_setProfile),
]);

关于dart - 如何在 Dart 中使用 `combineReducers` 指定类型注释?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54668893/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com