Flow报错[signature-verification-failure]:柯里化异步函数签名验证失败求助
解决Flow的signature-verification-failure错误
错误信息
type Submit = { form: any, handleSubmit: FunctionType<any, any>, ... } Flow-IDE Submit: type Submit = { form: any, handleSubmit: FunctionType < any, any > , ... } Cannot build a typed interface for this module. You should annotate the exports of this module with types. Missing type annotation at function return:Flow(signature-verification-failure) Cannot build a typed interface for this module. You should annotate the exports of this module with types. Missing type annotation at function return: [signature-verification-failure] (index.js:31:11)flow
问题代码
type Submit = { form: Object, handleSubmit: FunctionType<Object, any> // 自定义类型,可正常工作 }; export const onClickSubmit = ({ form, handleSubmit }: Submit) => async (input: Object): Promise<any> => { await handleSubmit(input); form.reset(); };
报错高亮在}: Submit)的右括号位置,尝试在):后添加类型定义无效。
解决方法
Flow需要明确标注导出函数的完整签名,包括外层函数的参数和返回的函数类型。可以通过以下两种方式修复:
方式一:定义类型别名后标注
type Submit = { form: Object, handleSubmit: FunctionType<Object, any> }; // 定义外层函数的完整类型 type OnClickSubmitType = (props: Submit) => (input: Object) => Promise<any>; export const onClickSubmit: OnClickSubmitType = ({ form, handleSubmit }) => async (input) => { await handleSubmit(input); form.reset(); };
方式二:直接标注完整类型
type Submit = { form: Object, handleSubmit: FunctionType<Object, any> }; export const onClickSubmit: (props: Submit) => (input: Object) => Promise<any> = ({ form, handleSubmit }) => async (input) => { await handleSubmit(input); form.reset(); };
说明
原代码中仅标注了内部异步函数的类型,但外层函数的完整签名未显式声明,导致Flow无法生成模块的类型接口。通过显式指定导出函数的完整类型,即可解决该错误。
内容的提问来源于stack exchange,提问作者Brandon
相关产品推荐
相关产品推荐

