From 1156a28de47f2ad1674f66e931946294ed827b97 Mon Sep 17 00:00:00 2001 From: Alan Bridgeman Date: Wed, 13 May 2026 15:17:35 -0500 Subject: [PATCH] Modified middleware typing so that it should be easier to use --- src/index.ts | 8 ++++---- test-harness/server.ts | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/index.ts b/src/index.ts index 55dd937..fc2f31b 100644 --- a/src/index.ts +++ b/src/index.ts @@ -166,7 +166,7 @@ async function initializeBAComponentsManualCopy(assets: { url: string | { script * @param options - An object containing the initialization options. * @returns A promise that resolves to either an Express middleware function or an object containing the library paths and render function. */ -export default async function initializeBAComponents(options: { expressApp?: Application, assets?: { url: string | { script: string, style: string }, file: string | { script: string, style: string } } } = {}): Promise { +export default async function initializeBAComponents(options: { expressApp?: Application, assets?: { url: string | { script: string, style: string }, file: string | { script: string, style: string } } } = {}): Promise { // Guard against "Both" if( ( @@ -183,16 +183,16 @@ export default async function initializeBAComponents(options: { expressApp?: App // --- STRATEGY A: Express Virtual Path --- if(typeof options.expressApp !== 'undefined') { - return await initializeBAComponentsExpressVirtualPath(options.expressApp); + return await initializeBAComponentsExpressVirtualPath(options.expressApp) as T; } // --- STRATEGY B: Manual Copy Strategy --- if(typeof options.assets === 'object' && options.assets !== null && typeof options.assets.url !== 'undefined' && typeof options.assets.file !== 'undefined') { - return await initializeBAComponentsManualCopy(options.assets); + return await initializeBAComponentsManualCopy(options.assets) as T; } // --- STRATEGY C: "Neither" (Framework Agnostic) --- // If no options are provided, just return the raw tools. // A Fastify or Koa user can use these to build their own integration. - return { paths: libraryPaths, render: coreRenderUI }; + return { paths: libraryPaths, render: coreRenderUI } as T; }; \ No newline at end of file diff --git a/test-harness/server.ts b/test-harness/server.ts index 94cc07c..5b45719 100644 --- a/test-harness/server.ts +++ b/test-harness/server.ts @@ -7,7 +7,7 @@ app.set('view engine', 'ejs'); app.set('views', './test-harness/views'); // Mount the library using your virtual path strategy -app.use(await baWebComponents({ expressApp: app }) as RequestHandler); +app.use(await baWebComponents({ expressApp: app })); app.get('/', (req: Request, res: Response) => { res.send('Hello from the test server! Navigate to /test/tooltip to see the tooltip component test page.');