gpt4 book ai didi

f# - 如何从 Fable 中的 NPM 模块导入函数?

转载 作者:行者123 更新时间:2023-12-01 10:24:39 26 4
gpt4 key购买 nike

我正在尝试使用 NPM 包 normalize-wheel在一个寓言项目中。
我已经确认包已经下载到node-modules文件夹。
符合documentationthis article我正在使用以下 F# 代码:

type INormalizedWheel =
abstract member pixelX: float
abstract member pixelY: float
abstract member spinX: float
abstract member spinY: float

[<Import("normalizeWheel", "normalize-wheel")>]
let normalizeWheel (we: React.WheelEvent) : INormalizedWheel = jsNative

...

let x = normalizeWheel wheelEvent
但是,只要到达最后一行,就会出现 JS 错误消息 "Object(...) is not a function"被抛出。在调试器中, normalizeWheel 的类型显示为 undefined .
我想导入不起作用,但我做错了什么?

最佳答案

我们来看看 normalize-wheel/index.js

module.exports = require('./src/normalizeWheel.js');

这告诉我们没有任何名为 normalizeWheel 的函数(否则它将是 module.exports.normalizeWheel = ...)。这意味着我们需要导入默认函数。这可以这样做:
[<Import("default", "normalize-wheel")>]
let normalizeWheel (we: React.WheelEvent) : INormalizedWheel = jsNative

// Or
let normalizeWheel (we: React.WheelEvent) : INormalizedWheel = importDefault "normalize-wheel"

关于f# - 如何从 Fable 中的 NPM 模块导入函数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48633043/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com