Skip to content

Commit

Permalink
fix: exclude typed body from cachedEventHandler
Browse files Browse the repository at this point in the history
  • Loading branch information
danielroe committed Aug 26, 2023
1 parent a0e60fd commit d2dcba1
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/runtime/cache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -195,11 +195,11 @@ export function defineCachedEventHandler<
>(
handler: EventHandler<Request, Response>,
opts?: CachedEventHandlerOptions<Response>
): EventHandler<Request, Response>;
): EventHandler<Omit<Request, 'body'>, Response>;
// TODO: remove when appropriate
// This signature provides backwards compatibility with previous signature where first generic was return type
export function defineCachedEventHandler<
Request = EventHandlerRequest,
Request = Omit<EventHandlerRequest, 'body'>,
Response = EventHandlerResponse,
>(
handler: EventHandler<
Expand Down
5 changes: 5 additions & 0 deletions test/fixture/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,11 @@ describe("defineCachedEventHandler", () => {
>
>();
});
it("should not allow typed input body", () => {
const b = defineCachedEventHandler<{ body: string }, Promise<{ message: string }>>(fixture);
// eslint-disable-next-line @typescript-eslint/ban-types
expectTypeOf(b).toEqualTypeOf<EventHandler<{}, Promise<{ message: string }>>>()
})
it("is backwards compatible with old generic signature", () => {
const a = defineCachedEventHandler<
Promise<{
Expand Down

0 comments on commit d2dcba1

Please sign in to comment.