Given a class defined in an external JS library (let's call it Foo) then I'd like to extend in F#
type bar() =
inherits Foo
...
However I can' only find examples of how to integrate with functions
and
[<Import("Foo", from="my-module")>]
let Foo = JsNative
will of course not let me derive Bar from Foo. So how Do I do that
The Import attribute can be used on a type declaration. e.g.
[<Import("Foo", from="my-module")>]
type Foo() =
class
end
type Bar() =
inherit Foo()
You can then also include signatures for the members of the class. It's instructive to look at examples of imports like the Fable React declarations: https://github.com/fable-compiler/fable-react/blob/master/src/Fable.React/Fable.Import.React.fs
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With