和其他的语言一样,在TypeScript中,命名空间是可以嵌套的。
如下:
namespace User {export let name = 'admin';export namespace Player {export let password = 'abc123'}}// 打印console.log(User.name); // adminconsole.log(User.Player.password); // abc123
需要注意的是,嵌套的作用域想要在外部使用,同样需要导出这个作用域。
