Fable: [ERROR] This expression was expected to have type 'obj' but here has type 'obj -> obj'

Created on 11 May 2017  路  2Comments  路  Source: fable-compiler/Fable

Repro code

module Main

open Fable.Core
open Fable.Core.JsInterop

let foo: obj = jsNative?bar

Description

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.

Related information

Most helpful comment

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:

All 2 comments

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, jsNative will 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:

Was this page helpful?
0 / 5 - 0 ratings

Related issues

tomcl picture tomcl  路  4Comments

forki picture forki  路  3Comments

ncave picture ncave  路  3Comments

alfonsogarciacaro picture alfonsogarciacaro  路  3Comments

rommsen picture rommsen  路  3Comments