![](/img/trans.png)
[英]How to reference Redux types in index.d.ts typescript definition file?
[英]How to split large typescript index.d.ts file
我们的应用程序有许多对象,我们可以大致分为3类; '核心','app'和'对象'。
我在网上跟踪了一个基本的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
}
}
但是由于我们使用了古老的源代码控制,将这个单个文件分解为3个单独的文件,包括应用程序,核心和对象,将“命名空间”作为ah.app.blah,ah.core.blah和ah.objects.blah。
我怎样才能做到这一点?
如果您没有在另一个项目中使用此库,则不需要声明模块。
看起来你有两个选择:
导出要在单独文件中公开的类型声明,并在需要时导入它们。 由于这似乎是最常见的做法,当您处理外部模块时,我认为这有我个人的偏好。
app.d.ts (~core.d.d,objects.d.ts)
export interface theAppInterface {}
src / index.ts (示例用法)
import { theAppInterface } from '../app' import { theCoreInterface } from '../core' let appUsage: ah.app.theAppInterface
在全局声明文件中声明单独的类别,因此它们被放入全局命名空间中,您不必在任何地方单独导入它们。 例如。
app.d.ts (~core.d.d,objects.d.ts)
declare namespace ah { namespace app { interface theAppInterface {} } }
SRC / index.ts
let appUsage: ah.app.theAppInterface let coreUsage: ah.core.theCoreInterface
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.