How to extend a JS class in fable

橙三吉。 提交于 2021-01-27 15:40:25

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!