Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Suggestion: Only create global variable for module if something tangible is exported #8668

Closed
zolem opened this issue May 18, 2016 · 4 comments
Labels
Suggestion An idea for TypeScript Too Complex An issue which adding support for may be too complex for the value it adds

Comments

@zolem
Copy link

zolem commented May 18, 2016

I think it would be great if when creating a module it would only create a global variable for that module if something tangible is exported. Whenever I use Typescript with angular I have no need for the global variable.

module a{
    export interface IController{
    }
    angular.module("module").controller("controller", Controller);
    class Controller{
    }
}

Nothing tangible is exported here so there is no need to create a global variable of "a".

The nice thing is I can still use the interfaces at design time because of the module and interface. But at runtime there is no need for the javascript variable to exist as it will just be an empty object anyway.

@RyanCavanaugh RyanCavanaugh added Suggestion An idea for TypeScript In Discussion Not yet reached consensus labels May 18, 2016
@RyanCavanaugh RyanCavanaugh added Too Complex An issue which adding support for may be too complex for the value it adds and removed In Discussion Not yet reached consensus labels Jun 9, 2016
@RyanCavanaugh
Copy link
Member

Discussed; this would complicate the emitter quite a bit and in the majority of cases there's going to be a global anyway. Workaround of using an IIFE seems acceptable now that local types are supported. #206 is related so if we get more use cases like this we can reconsider that one.

@zolem
Copy link
Author

zolem commented Jun 10, 2016

@RyanCavanaugh so can I still access the local classes/interfaces outside of an IIFE? With angular you still need the type hinting.

@RyanCavanaugh
Copy link
Member

You'd write e.g.:

module a{
    export interface IController{
    }
}
(() => {
    angular.module("module").controller("controller", Controller);
    class Controller implements a.IController {
    }
})();

@zolem
Copy link
Author

zolem commented Jun 13, 2016

@RyanCavanaugh Well at this point there is no need to make both a module and an IIFE. I might as well just use the module that is being created empty anyway as in the above comment. There would not be any benefit to your example over mine above that I can tell.

@microsoft microsoft locked and limited conversation to collaborators Jun 19, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Suggestion An idea for TypeScript Too Complex An issue which adding support for may be too complex for the value it adds
Projects
None yet
Development

No branches or pull requests

2 participants