Fable: dynamic cast operator !! lack of warnings during build!

Created on 4 Sep 2019  路  5Comments  路  Source: fable-compiler/Fable

Description

Following the docs here: https://fable.io/docs/communicate/js-from-fable.html#Plain-Old-JavaScript-Objects .

I was expecting the code below to raise warnings when building it!

Repro code

```f#

module App

open Fable.Core.JsInterop
open Fable.Import
open Fable.Core

type IMyInterface =
abstract foo: string with get, set
abstract bar: float with get, set
abstract baz: int option with get, set

// Warning, "foo" must be a string
let x: IMyInterface = !!{| foo = 5; bar = 4.; baz = Some 0 |}

// Warning, "bar" field is missing
let y: IMyInterface = !!{| foo = "5"; bAr = 4.; baz = Some 0 |}

// Ok, "baz" can be missing because it's optional
let z: IMyInterface = !!{| foo = "5"; bar = 4. |}

let print(x: IMyInterface) =
Browser.Dom.console.error(x)

print(x)
print(y)
print(z)
Browser.Dom.console.log(y)
Browser.Dom.console.log(z)
```

Expected and actual results

Expected a warning, got nothing.

Related information

$ npm show fable-compiler version

  • 2.3.23
  • Win 10 enterprise Insiders

All 5 comments

LOL, I expected even no warning, then I read the linked documentation.

I should have marked this feature as experimental ;)

It seems the F# compiler introduced some extra bindings to fix https://github.com/dotnet/fsharp/issues/6487 so Fable wasn't reading the AST properly. It will be fixed in the next Fable release :+1:

@alfonsogarciacaro thank you for the quick answer!

    type IMyInterface =
        abstract foo: string with get, set
        abstract bar: float with get, set
        abstract baz: int option with get, set

    type INoWarning =
        inherit IMyInterface
        abstract more : string with get, set
    // Warning, "more" is missing
    let p: INoWarning = !!{| foo = 5; bar = 4. |}
   // Warning, foo is the wrong type
    let r: INoWarning = !!{| more= ""; foo = 5; bar = 4. |}

    // Ok, all is fine!
    let q: INoWarning = !!{| more= ""; foo = "5"; bar = 4. |}

@alfonsogarciacaro I think I found an unexpected behavior with the code above!

The compiler only shows the first expected warning but not the second!
I am assuming it has to do with inheritance but I am not fully sure!

Let me know if I should open another issue :D

Yeah, I think we're not supporting interface inheritance in this feature yet. Ok, let's open again this issue and I'll have a look. Hopefully it's not too difficult to fix :)

Was this page helpful?
0 / 5 - 0 ratings

Related issues

SirUppyPancakes picture SirUppyPancakes  路  3Comments

ncave picture ncave  路  3Comments

alfonsogarciacaro picture alfonsogarciacaro  路  3Comments

et1975 picture et1975  路  3Comments

MangelMaxime picture MangelMaxime  路  3Comments