Skip to content

Add support for file include. #6616

@Izhaki

Description

@Izhaki

It seems that one of the likeable features of TypeScript, compared to Babel lets say, is that it emits readable code.

Consider the following code:

X.ts:

namespace a.b.x {
    class X {

    }
}

Y.ts:

namespace a.b.y {
    class y {

    }
}

This emits:

var a;
(function (a) {
    var b;
    (function (b) {
        var x;
        (function (x) {
            var X = (function () {
                function X() {
                }
                return X;
            })();
        })(x = b.x || (b.x = {}));
    })(b = a.b || (a.b = {}));
})(a || (a = {}));

var a;
(function (a) {
    var b;
    (function (b) {
        var y;
        (function (y_1) {
            var y = (function () {
                function y() {
                }
                return y;
            })();
        })(y = b.y || (b.y = {}));
    })(b = a.b || (a.b = {}));
})(a || (a = {}));

There's a lot of code redundancy, which can really clutter the emitted output for projects that rely heavily on namespaces.

Wouldn't it be nice if we could just do something like this:

namespace a.b {
    export namespace x {
        /// include X.ts
    }
    export namespace y {
        /// include Y.ts
    }
}

The include statement simply places the included file into the script during pre-compilation.

My guess is that this is already partly implemented with /// reference, only that ///reference doesn't seem to work unless it's either the first line, or one succeeding another /// reference.

Metadata

Metadata

Assignees

No one assigned

    Labels

    DeclinedThe issue was declined as something which matches the TypeScript visionDuplicateAn existing issue was already createdSuggestionAn idea for TypeScript

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions