当Typescript定义跨多个文件拆分时,使用插件修改模块
在TypeScript2.2中,我试图定义一个模块(HapiJS),它有各种插件选项 我将核心代码重构为多个.d.ts文件,然后使用以下模式()从index.d.ts导入并重新导出它们: 在一个单独的模块中,它扩展了它们:当Typescript定义跨多个文件拆分时,使用插件修改模块,typescript,plugins,typescript-typings,Typescript,Plugins,Typescript Typings,在TypeScript2.2中,我试图定义一个模块(HapiJS),它有各种插件选项 我将核心代码重构为多个.d.ts文件,然后使用以下模式()从index.d.ts导入并重新导出它们: 在一个单独的模块中,它扩展了它们: import*作为“hapi”中的hapi; 声明模块“hapi”{ 接口IFileHandler{ /**路径-如上所述的路径字符串或函数(必需)*/ 路径:string | IRequestHandler; ... } //扩展hapi核心: 接口路由配置{ 文件?:字符
import*作为“hapi”中的hapi;
声明模块“hapi”{
接口IFileHandler{
/**路径-如上所述的路径字符串或函数(必需)*/
路径:string | IRequestHandler;
...
}
//扩展hapi核心:
接口路由配置{
文件?:字符串| IRequestHandler | IFileHandler;
但是,当我这样做时,上面对
IRequestHandler
的所有引用都出现错误:“找不到名称'IRequestHandler'。如果所有的hapi代码都被移回一个巨大的index.d.ts中,那么它就会按预期工作。有没有办法使用多个hapi定义文件来实现这一点?我还没有尝试过,但也许可以使用以下内容(尽管我怀疑接口hapi.IRouteConfiguration{
是否可以接受):
import*作为“hapi”中的hapi;
声明模块“hapi”{
接口IFileHandler{
/**路径-如上所述的路径字符串或函数(必需)*/
路径:string | hapi.IRequestHandler;
...
}
//扩展hapi核心:
接口hapi.IRouteConfiguration{
文件?:字符串| hapi.IRequestHandler | IFileHandler;';
或者,可以从hapi/server
导入,或者从需要的任何部分导入
export * from './hapi/connection';
export * from './hapi/reply';
export * from './hapi/request';
export * from './hapi/response';
export * from './hapi/route';
export * from './hapi/server_views';
export * from './hapi/server';
import * as hapi from 'hapi';
declare module 'hapi' {
interface IFileHandler {
/** path - a path string or function as described above (required). */
path: string | IRequestHandler<string>;
...
}
// Extending hapi core:
interface IRouteConfiguration {
file?: string | IRequestHandler<string> | IFileHandler;
import * as hapi from 'hapi';
declare module 'hapi' {
interface IFileHandler {
/** path - a path string or function as described above (required). */
path: string | hapi.IRequestHandler<string>;
...
}
// Extending hapi core:
interface hapi.IRouteConfiguration {
file?: string | hapi.IRequestHandler<string> | IFileHandler;';