f# - 如何在寓言中扩展一个JS类

标签 f# fable-f#

给定一个在外部 JS 库中定义的类(我们称它为 Foo)然后我想在 F# 中扩展

type bar() = 
   inherits Foo
   ...

但是我只能找到如何与函数集成的示例

[<Import("Foo", from="my-module")>]
let Foo = JsNative

当然不会让我从 Foo 派生 Bar。那我该怎么做呢

最佳答案

Import 属性可用于type 声明。例如

[<Import("Foo", from="my-module")>]
type Foo() =
    class
    end

type Bar() =
    inherit Foo()

然后您还可以包括类(class)成员的签名。查看像 Fable React 声明这样的导入示例很有启发性:https://github.com/fable-compiler/fable-react/blob/master/src/Fable.React/Fable.Import.React.fs

关于f# - 如何在寓言中扩展一个JS类,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47640263/

相关文章:

f# - Deedle - 创建空列表和系列

f# - 错误 FS1133 : No constructors are available for the type 'List<' a>'

f# - 如何为 React 组件库编写 Fable 绑定(bind)

drop-down-menu - 如何在 Fable Elmish 的下拉菜单中设置默认值?

dictionary - 处理相同类型但不同形状的对象的惯用方法是什么?

arrays - F# 两个数组 - 第一个数组乘积按第二个数组上的索引过滤

c# - F# 类型到 Json 正在输出 Name@ 和 Name

f# - Fable F# > js 编译多个 .fsx 文件

f# - Fable-Elmish 中的渲染组件