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

Nested classes #1551

Closed
Serabass opened this issue Dec 24, 2014 · 4 comments
Closed

Nested classes #1551

Serabass opened this issue Dec 24, 2014 · 4 comments
Labels
Duplicate An existing issue was already created ES6 Relates to the ES6 Spec Needs Proposal This issue needs a plan that clarifies the finer details of how it could be implemented. Suggestion An idea for TypeScript

Comments

@Serabass
Copy link

Why Typescript has not the static classes like in Java, while Javascript has supported this.

If I wrote in JS:

    var ParentClass = (function () {
        function ParentClass() {

        }
        ParentClass.prototype.someMethod = function () {

        };

        ParentClass.StaticClass = (function () {
            function StaticClass() {

            }
            StaticClass.prototype.someMethodInStaticClass = function () {
                return "Hello, " + this.greeting;
            };

            return StaticClass;
        })();
        return ParentClass;
    })();

    var entity = new ParentClass.StaticClass();
    console.log(entity instanceof ParentClass.StaticClass); // true

This is correct, but:

    class parentClass {
        someMethod() {}

        {static} class StaticClass {
        someMethodInStaticClass() {}
        }
    }

    var entity = new ParentClass.StaticClass();
    console.log(entity instanceof ParentClass.StaticClass); // true

This is incorrect although it can compile into silimar JS.

P.S. I'm sorry for bad markup

@vilicvane
Copy link

for now you may use something like this:

class Parent {

}

module Parent {
    export class Child {
        someMethod() { }
    }
}

@Serabass
Copy link
Author

I know this. But Javascript can generate multi-level tree of classes. I want see it in Typescript ;)

@DanielRosenwasser
Copy link
Member

I think this would be fulfilled by ES6 class expressions (see #497).

@RyanCavanaugh RyanCavanaugh added ES6 Relates to the ES6 Spec Suggestion An idea for TypeScript Needs Proposal This issue needs a plan that clarifies the finer details of how it could be implemented. labels Dec 30, 2014
@RyanCavanaugh RyanCavanaugh changed the title Static classes? Nested classes Dec 30, 2014
@danquirk
Copy link
Member

danquirk commented Jan 6, 2015

Agreed, just gonna close this as a duplicate of #497 unless someone has a very compelling reason for additional syntax on top of that.

@danquirk danquirk closed this as completed Jan 6, 2015
@danquirk danquirk added the Duplicate An existing issue was already created label Jan 6, 2015
@DanielRosenwasser DanielRosenwasser removed the ES6 Relates to the ES6 Spec label Jan 13, 2015
@DanielRosenwasser DanielRosenwasser added the ES6 Relates to the ES6 Spec label Jan 26, 2015
@microsoft microsoft locked and limited conversation to collaborators Jun 18, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Duplicate An existing issue was already created ES6 Relates to the ES6 Spec Needs Proposal This issue needs a plan that clarifies the finer details of how it could be implemented. Suggestion An idea for TypeScript
Projects
None yet
Development

No branches or pull requests

5 participants