[英]How to split large typescript index.d.ts file
Our application has many objects and such like that we can roughly break down into 3 categories; 我们的应用程序有许多对象,我们可以大致分为3类; 'core', 'app' and 'objects'. '核心','app'和'对象'。
I followed a basic Typescript tutorial online and currently there is a single index.d.ts which has this kind of layout: 我在网上跟踪了一个基本的Typescript教程,目前有一个index.d.ts,它有这种布局:
interface AH {
}
declare var ah: AH;
declare module 'ah' {
export = ah;
}
declare module ah {
module objects {
// much objects
}
module app {
//many app
}
module core {
//such core
}
}
However due to the archaic source control we use, it would be beneficial to break this single file out to 3 separate files for app, core and objects, having the "namespaces" available as ah.app.blah, ah.core.blah and ah.objects.blah. 但是由于我们使用了古老的源代码控制,将这个单个文件分解为3个单独的文件,包括应用程序,核心和对象,将“命名空间”作为ah.app.blah,ah.core.blah和ah.objects.blah。
How can I achieve this? 我怎样才能做到这一点?
If you are not using this library in another project, there is no need the declare modules. 如果您没有在另一个项目中使用此库,则不需要声明模块。
It seems like you have two options here: 看起来你有两个选择:
Export the type declarations you want to expose in separate files, and import them when you need them. 导出要在单独文件中公开的类型声明,并在需要时导入它们。 As this seems to be the most common practice, also when you are handling external modules, I think this has my personal preference. 由于这似乎是最常见的做法,当您处理外部模块时,我认为这有我个人的偏好。
app.d.ts (~ core.d.ts, objects.d.ts) app.d.ts (~core.d.d,objects.d.ts)
export interface theAppInterface {}
src/index.ts (example usage) src / index.ts (示例用法)
import { theAppInterface } from '../app' import { theCoreInterface } from '../core' let appUsage: ah.app.theAppInterface
Declare the separate categories in global declaration files, so they're thown into the global namespace and you don't have to import them separately everywhere. 在全局声明文件中声明单独的类别,因此它们被放入全局命名空间中,您不必在任何地方单独导入它们。 Eg. 例如。
app.d.ts (~ core.d.ts, objects.d.ts) app.d.ts (~core.d.d,objects.d.ts)
declare namespace ah { namespace app { interface theAppInterface {} } }
src/index.ts SRC / index.ts
let appUsage: ah.app.theAppInterface let coreUsage: ah.core.theCoreInterface
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.