简体   繁体   English

将停止使用 TypeScript 命名空间?

[英]TypeScript namespaces to be discontinued?

Recently, I read a quite a bit from developers who suggest not to use namespaces any more but switching to modern module handling.最近,我从开发人员那里读了很多,他们建议不要再使用命名空间,而是切换到现代模块处理。 I'm teaching programming to beginners using TypeScript and namespaces are very valuable here, since folks can work on multiple assignments over a longer period of time in a single directory and subdirectories, without having to deal with multiple compiler configuration files and module exports and imports.我正在使用 TypeScript 向初学者教授编程,命名空间在这里非常有价值,因为人们可以在一个目录和子目录中在更长的时间内处理多个任务,而无需处理多个编译器配置文件和模块导出和导入. They just define a namespace for a task and use that across the files they create for it.他们只是为一个任务定义一个命名空间,并在他们为它创建的文件中使用它。

So my question is: are there plans to discontinue namespaces in TypeScript?所以我的问题是:是否有计划在 TypeScript 中停止命名空间?

So my question is: are there plans to discontinue namespaces in TypeScript?所以我的问题是:是否有计划在 TypeScript 中停止命名空间?

Probably not.可能不是。 Here is a comment of a Microsoft staff about another subject but it seems it is a general remark:这是微软员工对另一个主题的评论,但似乎是一般性评论:

This is not the TS team position.这不是TS团队的立场。 we have no plans of deprecating any thing any time soon.我们没有计划在短期内弃用任何东西。 ( source ) 来源

Anyway, the ES6 module system is the way to go.无论如何,ES6 模块系统是要走的路。 I suggest an article from Mozilla on how to import a module as a namespace:我推荐Mozilla 的一篇关于如何将模块作为命名空间导入的文章

When you import * , what's imported is a module namespace object .当您import * ,导入的是一个模块命名空间对象 Its properties are the module's exports.它的属性是模块的导出。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM