重载$ Call进行条件类型解析

时间:2019-02-17 20:19:39

标签: flowtype

我想知道是否有可能引入一些条件逻辑来根据输入类型产生$Call的返回类型。

我能想到的一个简单示例是获取Flow类型的字符串。

// @flow

type Options = {|
  foo: string,
  bar: number
|}

type ExtractReturnType = <V: number>(V) => 'number' & <V: string>(V) => 'string'

type $Extract = $ObjMap<Options, ExtractReturnType>

const f: $Extract = {
  foo: ('string': 'string'),
  bar: ('number': 'number')
}

0 个答案:

没有答案