你能在TypeScript中创建嵌套类吗? [英] Can you create nested classes in TypeScript?

查看:513
本文介绍了你能在TypeScript中创建嵌套类吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法在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();


推荐答案

从TypeScript 1.6开始,我们有类表达式(参考)。

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

这篇关于你能在TypeScript中创建嵌套类吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆