Skip to content

Commit

Permalink
fixing middyjs#1228
Browse files Browse the repository at this point in the history
  • Loading branch information
jerizm committed Sep 18, 2024
1 parent 4ad95ba commit 43dfbdf
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
6 changes: 3 additions & 3 deletions packages/core/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,12 +96,12 @@ export interface MiddyfiedHandler<
before: AttachMiddlewareFn<TEvent, TResult, TErr, TContext, TInternal>
after: AttachMiddlewareFn<TEvent, TResult, TErr, TContext, TInternal>
onError: AttachMiddlewareFn<TEvent, TResult, TErr, TContext, TInternal>
handler: <TInputHandlerEventProps = TEvent, TInputHandlerResultProps = TResult>(
handler: <TInputHandlerEventProps = TEvent>(
handler: MiddlewareHandler<
LambdaHandler<TInputHandlerEventProps, TInputHandlerResultProps>,
LambdaHandler<TInputHandlerEventProps, TResult>,
TContext
>
) => MiddyfiedHandler<TInputHandlerEventProps, TInputHandlerResultProps, TErr, TContext, TInternal>
) => MiddyfiedHandler<TInputHandlerEventProps, TResult, TErr, TContext, TInternal>
}

declare type AttachMiddlewareFn<
Expand Down
19 changes: 19 additions & 0 deletions packages/core/index.test-d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -409,3 +409,22 @@ const s3Handler = async (event: S3Event): Promise<void> => {

const handler1182 = middy().handler(s3Handler)
expectType<MiddyfiedHandler<S3Event, void, Error, Context, {}>>(handler1182)

let handler1228 = middy<APIGatewayProxyEvent, APIGatewayProxyResult, Error, Context>();
// @ts-expect-error - should enforce the return type
handler1228.handler(async (req, context) => {
return '123';
});

handler1228.handler(async (event) => {
return {
statusCode: 200,
body: `Hello from ${event.path}`
};
});

// @ts-expect-error - should enforce the return type
handler1228.handler<APIGatewayProxyEvent>(async (req, context) => { return '123'; });

// @ts-expect-error - can't change the return type
handler1228.handler<APIGatewayProxyEvent, string>(async (event) => { return { statusCode: 200, body: `Hello from ${event.path}` }; });

0 comments on commit 43dfbdf

Please sign in to comment.