在Prom中使用Promise作为返回类型 [英] Using Promise as return type in Flow
问题描述
我正在使用Flow 0.30.0。我有一个函数返回一个promise:
I'm using Flow 0.30.0. I have a function that returns a promise:
function process(callback:Function):Promise {
return new Promise((r,re) => callback)
}
Flow引发错误,抱怨:
Flow raises an error, complaining:
function process(callback:Function):Promise {
^^^^^^^ Promise. Application of polymorphic type needs <list of 1 argument>. (Can use `*` for inferrable ones)
这适用于尝试流程,但不在本地。问题的任何想法?
This works in Try Flow, but not locally. Any ideas of the issue?
推荐答案
根据流程更改日志,v0.28.0中引入了一个更改,它使类型参数显式化。明确将返回类型设置为 Promise< any>
应该可以解决您的问题。
According to the flow changelog there was a change introduced in v0.28.0 which made type arguments explicit. Explicitly setting the return type to Promise<any>
should fix your issue.
或者您可以将以下标志设置为false,尽管这是一个临时标志,将来会被删除
Alternatively you can set the following flag to false, although this is a temporary flag which will be removed in the future
experimental.strict_type_args = false
https://github.com/facebook/flow/blob/master/Changelog.md#v0280
这篇关于在Prom中使用Promise作为返回类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!