我有一个相当简单的javascript方法
var agent = new Agent(1,"John Doe", "France");
console.log(agent.agentCountry); //Displays "France"
agent.setAgentCountry();
console.log(agent.agentCountry); //Did not display the table of countries it should
这是在javascript土地上工作。我试图将其转换为寓言,但要么我可以让它拥有对(props,propName,componentName) => {
var value = props[propName];
const getOrSpread = name =>
props[name] || props.spread && props.spread[name];
// remainder of function code omitted
}
的绝对存在的属性访问权限,或者对.spread
的动态访问权限,而不是两者都
props[propName]
如果props被定义为IReactProps,则.spread起作用,但两个可能的module JsxHelpers =
type IReactProps =
abstract member spread : obj
let isfuncOrNullPropType (props:IReactProps) (propName:string) componentName =
let propsO :obj = box props
let value:obj = propsO?propName
let valueAttempt2:obj = (box props)?(propName)
// rest of translation not attempted yet
value
都没有编译。
或者道具被定义为let value lines
并且它表示“这个表达式应该具有类型' obj'但这里有类型'' a - >物镜'
即使文档中最简单的对象似乎也没有编译:
obj
使用let isfuncOrNullPropType (props:obj) (propName:string) =
let value2:obj = props?propName
value2
答案 0 :(得分:0)
您肯定需要根据文档将道具名称放在括号中。您获得的编译器错误是因为props?(propName)
返回类型'a -> obj
。显然,动态(?
)运算符返回Applicable
,并从寓言源中返回:
/// DO NOT USE: Internal type for Fable dynamic operations
type Applicable = obj->obj
也许试试:
let value : obj = unbox<obj> (props?(propName))