如何将TypeScript类拆分为多个文件? [英] How do I split a TypeScript class into multiple files?

查看:1363
本文介绍了如何将TypeScript类拆分为多个文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我找到了很多例子,并尝试将模块分成几个文件。所以我得到那个,非常方便。但是出于同样的原因,有时候分割课程也很实际。假设我有几种方法,我不想将所有内容都塞进一个长文件中。

I found a lot of examples and also tried myself to split a module into several files. So I get that one, very handy. But it's also practical sometimes to split a class for the same reason. Say I have a couple of methods and I don't want to cram everything into one long file.

我正在寻找类似于 partial <的东西/ strong> C#中的声明。

I'm looking for something similar to the partial declaration in C#.

推荐答案

你不能。

有一个功能请求实现了部分类,首先是在 CodePlex 上,稍后是 GitHub ,但在2017-04-04上它被宣布超出范围。给出了很多原因,主要的理由是它们希望尽可能避免偏离ES6:

There was a feature request to implement partial classes, first on CodePlex and later on GitHub, but on 2017-04-04 it was declared out-of-scope. A number of reasons are given, the main takeaway seems to be that they want to avoid deviating from ES6 as much as possible:


TypeScript 已经有太多特定于TS的类功能[...]添加另一个特定于TS的类功能是骆驼背上的另一根稻草,我们应该尽可能避免。 [...]因此,如果某些场景确实将其从公园中推出以添加部分类,那么该场景应该能够通过TC39过程证明自己的合理性。

TypeScript already has too many TS-specific class features [...] Adding yet another TS-specific class feature is another straw on the camel's back that we should avoid if we can. [...] So if there's some scenario that really knocks it out of the park for adding partial classes, then that scenario ought to be able to justify itself through the TC39 process.

这篇关于如何将TypeScript类拆分为多个文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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