首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >与未来一起使用

与未来一起使用
EN

Stack Overflow用户
提问于 2020-01-19 08:00:32
回答 1查看 1.6K关注 0票数 2

我想使用dartz函数样式并执行如下操作:

代码语言:javascript
复制
Either<Failure, Response> result = await remoteDataSource.request() // Future<Response> request();
    .then((response) => Right(response))
    .catchError((failure) => Left(failure));

但我似乎不能这么做

错误:类型'Right< dynamic,Response>‘的值不能分配给'Either< Failure,Response>’类型的变量。

那么,如何以这种方式将EitherFuture结合使用呢?

EN

回答 1

Stack Overflow用户

发布于 2020-03-08 17:29:27

这都是关于<generics>的。

代码语言:javascript
复制
.then((response) => Right(response)) // this is of type Right<dynamic,User>

您必须向编译器提供所有正确的信息:

代码语言:javascript
复制
.then((response) => Right<Failure, Response>(response))

// or

.then((response) => right(response)) // a helper function which returns an Either
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/59808248

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档