Skip to content

Smarter compiler to create Internal and External Modules from the same TypeScript file. #519

@codeBelt

Description

@codeBelt

Currently, you have to write TypeScript files two different ways to either output them as Internal or External Modules. Can we have a smarter compiler that can create an Internal or External Modules from the same TypeScript file using the module option?

Suggestion, create all classes in the internal module way.

module namespace {
    export class ClassName {
        constructor() {
        }
        public methodName():void {
        }
    }
}

which would create the modular version

define(["require", "exports"], function(require, exports) {
    var ClassName = (function () {
        function ClassName() {
        }
        ClassName.prototype.methodName = function () {
        }
        return ClassName;
    })();
    return ClassName;
});

or could create a none modular version from the same file.

var namespace;
(function (namespace) {
    var ClassName = (function () {
        function ClassName() {
        }
        ClassName.prototype.methodName = function () {
        };
        return ClassName;
    })();
    namespace.ClassName = ClassName;
})(namespace || (namespace = {}));

Initially I created a framework using the internal module way but then had to port it to the external module way for another project. Now I am maintaining two code bases and the only difference is how the files are structured so that I can create an internal or external module versions.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Out of ScopeThis idea sits outside of the TypeScript language design constraintsSuggestionAn idea for TypeScript

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions