问题描述
给出一个在外部JS库中定义的类(我们称其为Foo),然后我想在F#中进行扩展
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
和
[<Import("Foo", from="my-module")>]
let Foo = JsNative
当然不会让我从Foo派生Bar.那我该怎么做
will of course not let me derive Bar from Foo. So how Do I do that
推荐答案
Import
属性可用于 type
声明.例如
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()
然后,您还可以包括班级成员的签名.查看诸如Fable React声明之类的导入示例很有启发性: https://github.com/fable-compiler/fable-react/blob/master/src/Fable.React/Fable.Import.React.fs
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
这篇关于如何在寓言中扩展JS类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!