basarat basarat - 4 months ago 43
Javascript Question

Can you create nested classes in TypeScript?

Is there a way to nest classes in TypeScript. E.g. I'd like to use them like:

var foo = new Foo();
var bar = new Foo.Bar();

Answer

Starting with TypeScript 1.6 we have class expressions (reference).

This means you can do the following :

class Foo {
    static Bar = class {

    }
}

// works!
var foo = new Foo();
var bar = new Foo.Bar();
Comments