【发布时间】:2018-10-31 02:28:32
【问题描述】:
在流类型检查器中,如何根据参数对象属性定义函数响应类型。这是一个例子:
function test(argument) {
if (argument.responseType === "string") {
return "Some string value"
}
return { some: { json: "object" } };
}
是否可以在此代码中添加流类型?
我知道可以写:
declare export function test(argument: { responseType: string}): string | { some: { json: string } };
但这还不够。我不想要Union Type 回复。根据提供的参数,它必须是字符串或对象。
【问题讨论】:
标签: javascript flowtype