module Main
open Fable.Core
open Fable.Core.JsInterop
let foo: obj = jsNative?bar
I get this error:
ERROR in ./Main.fsproj
/Main.fs(6,15,6,27) : error FSHARP: This expression was expected to have type
'obj'
but here has type
'obj -> obj'
@ multi babel-polyfill ./Main.fsproj
Is this expected behavior? I thought that the ? syntax can be used for both property lookups and method calls, but it seems not.
[email protected][email protected]This is a trick I had to do to make dynamic properties directly applicable. So you can do foo?bar(1,2) instead of using an intermediate operator like before foo?bar$(1,2). I've filled an F# language suggestion to avoid the need of having the result of ? be of obj->obj type.
For now, you can just use dynamic cast in these cases: let foo: obj = !!myObj?bar
BTW,
jsNativewill throw an exception. I guess you want something else there.
The jsNative was just to create the smallest possible repro code, in a real app it would use proper JS interop.
Thanks for filing an issue! :heart:
Most helpful comment
The
jsNativewas just to create the smallest possible repro code, in a real app it would use proper JS interop.Thanks for filing an issue! :heart: