我只想导出一个Typescript模块中的所有内容,例如我声明一个这样的模块:
/// <reference path='../d.ts/DefinitelyTyped/node/node.d.ts' />
/// <reference path='../d.ts/DefinitelyTyped/express/express.d.ts' />
/// <reference path='../d.ts/DefinitelyTyped/mongoose/mongoose.d.ts' />
import express = require("express");
import mongoose = require("mongoose");
export module Users {
export var users: Express = express();
export var base_URL: string = "/users";
users.get(base_URL, (req, res) => {
res.render("index", {
title: "Cheese cakes"
});
});
}
现在,正如您所看到的那样,为了访问base_URL
和users
,我还需要明确导出它们。我该怎么说,我想导出模块内的所有内容。
答案 0 :(得分:2)
默认情况下,模块内的项目是私有的,除非您explicitly
导出它们。
PS:将NodeJS与TypeScript一起使用时,声明内部模块几乎没有什么优势。 nodeJS中的每个文件都是一个模块,只有explicitly
导出的内容在导入位置可用。所以我会写:
/// <reference path='../d.ts/DefinitelyTyped/node/node.d.ts' />
/// <reference path='../d.ts/DefinitelyTyped/express/express.d.ts' />
/// <reference path='../d.ts/DefinitelyTyped/mongoose/mongoose.d.ts' />
import express = require("express");
import mongoose = require("mongoose");
export var users: Express = express();
export var base_URL: string = "/users";
users.get(base_URL, (req, res) => {
res.render("index", {
title: "Cheese cakes"
});
});