【发布时间】:2017-05-06 12:23:06
【问题描述】:
我用flowType写express router代码,让flow检查req.body数据,body数据有多种类型,如UserData(bbb type)或LoginData(ccc type)。但是当身体将数据转换为功能时,流程总是说错了。有没有什么好主意来支持 body 有多种类型检查?这是一个演示错误代码。
/* @flow */
declare type ccc = {
ccc: string;
}
declare type bbb = {
bbb: string;
}
declare type aaa = {
body: bbb | ccc
}
function test(aaa: aaa) {
const body = aaa.body
test2(body)
}
function test2(body: ccc): string {
return body['ccc']
}
【问题讨论】:
-
如果您编辑问题以包含完整的错误文本,那么有人会更容易快速帮助您。
标签: javascript flowtype flow-typed