Skip to content

Commit

Permalink
fix: exclude typed body from cachedEventHandler (#1647)
Browse files Browse the repository at this point in the history
  • Loading branch information
danielroe authored Aug 26, 2023
1 parent a0e60fd commit b470fd0
Show file tree
Hide file tree
Showing 2 changed files with 12 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
10 changes: 10 additions & 0 deletions test/fixture/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,16 @@ describe("defineCachedEventHandler", () => {
>
>();
});
it("should not allow typed input body", () => {
const b = defineCachedEventHandler<
{ body: string },
Promise<{ message: string }>
>(fixture);
expectTypeOf(b).toEqualTypeOf<
// eslint-disable-next-line @typescript-eslint/ban-types
EventHandler<{}, Promise<{ message: string }>>
>();
});
it("is backwards compatible with old generic signature", () => {
const a = defineCachedEventHandler<
Promise<{
Expand Down

0 comments on commit b470fd0

Please sign in to comment.