【发布时间】:2019-04-09 12:08:39
【问题描述】:
Flow 是否应该检查返回类型?它似乎不适用于自定义类型 - 以下代码编译得很好:
function test1(value: number) : Distance {
if (value == 4) {
return "asd";
}
if (value == 5) {
return { a: 9 };
}
if (value == 6) {
return null;
}
return new Distance(value);
};
距离定义如下:
export class Distance {
value: string;
unit: string;
constructor(value: string, unit?: SDKConstants.MeasurementUnit) {
this.value = value;
this.unit = unit;
}
}
这在 Flow 上编译得很好。我注意到如果我将返回类型更改为数字,则会出现一些错误。
有人能解释一下 Flow 在这种情况下的局限性吗?我需要在配置中进行设置以使其更严格还是什么?
【问题讨论】:
标签: javascript react-native flowtype