是否可以使一种类型的类型基于另一种类型的值?

时间:2018-07-26 16:26:59

标签: javascript reactjs flowtype

我有一个接受tagType道具的组件。如果该标签类型为链接 a ,则需要link道具。如果tagType按钮输入,则不需要link道具。

这是我到目前为止的内容,但无法弄清楚如何设置link的类型:

type linkTagTypes = 'Link' | 'a'
type nonLinkTagTypes = 'button' | 'input'

type tProps = {
  tagType: linkTagTypes | nonLinkTagTypes,
  link: string,
   ...
}

1 个答案:

答案 0 :(得分:1)

一种可能性是使用联合类型,但不使用data = chart.aggregate([{ $project: { isoDate: { $add: [new Date(0), { $multiply: [ 1000, "$created_on"]} ] } } }, { $project: {month: { $month: "$isoDate"} } },{ $group: { _id: "$month",count: {$sum: 1} } }]) output = [] trs = "" for x in data: #output.append((stage1)) #data = chart.aggregate([{"$group": {"_id":"$created_on"}}]) # created_on = x['created_on'] # trs += "<tr><td>"+str(created_on)+"</td></tr>" # #print str(output) labels = ["January","February","March","April","May","June","July","August","September","October","November","December"] #values = [10,9,8,7,6,4,7,8] return render_template('chart.html', values=x, labels=labels) 属性,而是使用tagType属性,如下所示:

tProps

检查该游乐场的用途:Make link required only in one case