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

Proposal. Internal class declaration. #4460

Closed
xLama opened this issue Aug 26, 2015 · 2 comments
Closed

Proposal. Internal class declaration. #4460

xLama opened this issue Aug 26, 2015 · 2 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

@xLama
Copy link

xLama commented Aug 26, 2015

I think it´s a good idea to let an internal class declaration:

class A{
   class B{}
}

Emit proposal:

var A = (function () {

     var B = (function () {
    function B() {
    }
    return B;
})();


    function A() {
    }
    return A;
})();

We can use it to make Singleton very easy.

class Singleton{

    class B{
        private enforcer:string;
    }

    private static _instance:Singleton;

    constructor(enforcer: B){}

    public static get instance():Singleton{
        if (Singleton._instance === undefined){
            Singleton._instance = new Singleton(new B())
        }
        return Singleton._instance;
    }
}

Related: #3266

@kitsonk
Copy link
Contributor

kitsonk commented Aug 26, 2015

How would you propose emitting this when targeting ES6, since that isn't valid ES6?

@RyanCavanaugh RyanCavanaugh added Suggestion An idea for TypeScript Too Complex An issue which adding support for may be too complex for the value it adds labels Aug 26, 2015
@RyanCavanaugh
Copy link
Member

This doesn't add enough value over already-supported local types:

class A {
    static B = class {
        x;
        y;
    }

    getInstance() {
        return new A.B();
    }
}

@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

3 participants