diff --git a/runtimes/js/encore.dev/api/mod.ts b/runtimes/js/encore.dev/api/mod.ts index 95e3b5c06c..14b6e100e5 100644 --- a/runtimes/js/encore.dev/api/mod.ts +++ b/runtimes/js/encore.dev/api/mod.ts @@ -30,10 +30,7 @@ export interface APIOptions { auth?: boolean; } -export type Handler< - Params extends object | void = void, - Response extends object | void = void -> = Params extends void +type HandlerFn = Params extends void ? () => Promise : (params: Params) => Promise; @@ -42,8 +39,17 @@ export function api< Response extends object | void = void >( options: APIOptions, - fn: Handler -): Handler { + fn: (params: Params) => Promise +): HandlerFn; + +export function api< + Params extends object | void = void, + Response extends object | void = void +>( + options: APIOptions, + fn: (params: Params) => Response +): HandlerFn; +export function api(options: APIOptions, fn: any): typeof fn { return fn; }