我试图在寓言项目中使用NPM包normalize-wheel。
我已确认该软件包已下载到node-modules
文件夹。
与使用以下F#代码的documentation和this article一致:
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
。
我猜导入无效,但我做错了什么?
答案 0 :(得分:6)
让我们来看看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"