说我有一个功能:对象类型flowjs
const example = (item : ?{+type?: ?string}) : {+result: ?string} => {
const state = {}
state.result = item.result
return state
}
这失败,给类型检查:
12: state.result = item.result
^^^^^^^ property `result`. Property not found in
12: state.result = item.result
^^^^^^ object type
为什么没有这种类型检测?我没有用确切的对象类型符号?{|+type?: ?string|}
来定义类型,所以它不应该允许其他键吗?那么确切的对象符号如何工作呢?我怎样才能定义这样的部分对象类型?这甚至有可能吗?
您的参数'item'没有名为'result'的属性。你是不是要编写'state.result = item.type'呢? (尽管你还需要在那里进行空检查)。 –
如果我的问题不清楚,请随时编辑。我的意思是这个对象中可能有很多键,并不是我可能会列举的所有键,我不明白为什么流没有使用“确切对象”符号来检查类型。任何方式,我可以澄清这个问题(随意编辑的方式!) –