Can you create nested classes in TypeScript?

后端 未结 4 999
情歌与酒
情歌与酒 2020-12-08 03:49

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();
4条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-12-08 04:11

    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();
    

提交回复
热议问题