During my exploration of Typescript 2.2, I encountered a challenge in defining a module for HapiJS with various plugin options.
To streamline the core code, I split it into multiple .d.ts files and then imported and re-exported them all from the index.d.ts using this specific pattern (view here):
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';
In another module, I extended them as shown 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;
However, after implementing this structure, all references to IRequestHandler
resulted in an error stating: "Cannot find name 'IRequestHandler'." Moving all the hapi code back into one large index.d.ts file resolved this issue. Is there a way to make this work with multiple hapi definition files?