1

I just want to export everything inside a Typescript Module, say for example I declare a module like this:

/// <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"
        });
    });
}

Now, as you can see in order to get access to base_URL and users, I need to export them explicitly as well. What can I do to say, that I want to export everything inside a module.

1 Answer 1

2

Items inside a module are private by default unless you explicitly export them.

PS: there is little advantage of declaring an internal module when using nodeJS with TypeScript. Each file in nodeJS is a module and only things you explicitly export are available at the import location. So I would write:

/// <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"
    });
});
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.