0
我正在尝试使用打印机获取简单的节点项目,并使用共享模块将代码分解为两个单独的文件。但有一些问题!文件之间的打字稿模块
1)FileReader.ts
限定+出口共享模块
var fs = require("fs");
export module Qbot {
export class Utils {
static read(filename: string) {
var buf = fs.readFileSync(filename, "utf8");
return data;
}
}
Qbot.Utils.read("test"); // compiles OK
}
2)内的静态功能的单独的文件中,试图用上面。
/// <reference path="./FileReader.ts" />
// should be in same module but TS compiler gives an error
module Qbot {
var u = Qbot.Utils; // ERR does not exist
var data = Qbot.Utils.read("somefile.json"); // ERR cant find name
}
// outside the module? nope.
var data = Qbot.Utils.read("somefile.json"); // Utils doesnt exist
// this works but why the extra file thingy needed?
import something = require("./FileReader");
var filepath = "./topics.json";
var data = something.Qbot.Utils.read(filepath);
在我可以访问它们之前,是否需要将额外的文件导入“包含”导入模块?任何关于如何实现这一点的指针将不胜感激!
这个例子也只是想叫Qbot.Utils模块上的静态函数(按照本例https://stackoverflow.com/a/13212648/1146785)
谢谢!
更新我可以用'export = Qbot' – dcsan