2017-04-07 26 views
0

In Typescript 2.2我试图定义一个模块(HapiJS),它有各种插件选项。当Typescript定义跨多个文件拆分时,使用插件修改模块

我重构的核心代码分成多个文件.d.ts然后导入并使用下述模式(as seen here)再出口它们全部来自index.d.ts:

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'; 

在一个单独的模块,它扩展了他们as seen here

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; 

然而,当我这样做的所有引用IRequestHandler上面的错误:“无法找到名为‘IRequestHandler’。”如果所有的hapi代码都被移回到一个巨大的index.d.ts中,那么它就像预期的那样工作。有没有办法实现这个使用多个hapi定义文件?

回答

0

我还没有尝试过了,但也许有可能使用类似下面的(虽然我怀疑interface hapi.IRouteConfiguration {是可以接受的):

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;'; 

或者也许是从hapi/server进口,或任何部分是必要的。

相关问题