问题
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
回答1:
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
来源:https://stackoverflow.com/questions/47640263/how-to-extend-a-js-class-in-fable