1

我只想导出 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_URLand users,我还需要明确地导出它们。我能说什么,我想导出模块内的所有内容。

4

1 回答 1

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"
    });
});
于 2013-08-26T12:01:27.620 回答