我正在尝试使用 typescript 中的 momentJs:根据我用来编译 typescript 的模块系统,我发现了关于如何使用 momentJs 的不同行为。使用commonJs编译 typescript 时,一切都按预期工作,我可以按照 momentJs 文档进行操作:
import moment = require("moment");
moment(new Date()); //this works
如果我在导入“时刻”时使用“系统”作为打字稿模块系统,我将被迫这样做
import moment = require("moment");
moment.default(new Date()); //this works
moment(new Date()); //this doesn't work
我找到了一种解决方法,无论使用什么打字稿模块系统,它们都可以工作
import m = require("moment")
var moment : moment.MomentStatic;
moment = (m as any).default || m;
我不喜欢这样,我想了解它为什么会这样。难道我做错了什么?谁能解释我发生了什么?