【发布时间】:2017-05-09 15:34:13
【问题描述】:
根据参数类型具有不同返回类型的多态方法指定类型定义的正确方法是什么?
index.js:
// @flow
import {func1} from './lib1';
const s: string = func1('string');
const b: boolean = func1(); // should cause type error but does not!
lib1.js:
export function func1(p) {
return (typeof p === 'string') ? p : 0;
}
defs/lib1.js.flow
// @flow
declare module "lib1" {
declare export function func1(p: string): string;
declare export function func1(_: void): number;
}
.flowconfig:
[libs]
defs/
我希望在 index.js(4) 中收到错误消息,但 flow 不会抱怨!
【问题讨论】:
标签: flowtype flow-typed