1
我想知道如何将一个Object
铸造成Flow中用户定义的精确类型。例如:是否可以在Flow中将对象转换为确切类型?
//@flow
type exactType = {|x : number|}
function test(a : Object) : exactType {
if(typeof(a.x) === 'string'){
return (a : exactType);
}
throw new Error('Incorrect type!')
}
甚至可以写这样的函数吗?即是否可以为类型检查器提供参数a
只有一个字段,名称为x
,类型为number
?