Skip to content

InferProps keeps Promise and Response for a withValidator loader #478

Closed

Description

@ashunar0

InferProps gives the props of a defineHandler loader, but not of a defineHandler.withValidator one:

export const loader = defineHandler.withValidator({
  params: z.object({ id: z.string() }),
})(async (c, { params }) => {
  const book = await findBook(params.id);
  if (!book) return c.notFound();
  return { book };
});

type Props = InferProps<typeof loader>;
// expected: { book: Book }
// actual:   Promise<Response | { book: Book }>

defineHandler returns TypedHandler<{}, Exclude<Awaited<R>, Response>>, but withValidator returns TypedHandler<V, R> with the raw R. Routes don't notice, because the generated types wrap the output in Serialize<Awaited<…>>. InferProps reads __output directly, so it breaks.

Returning Exclude<Awaited<R>, Response> from withValidator too fixes it. Fix and a type test: ashunar0@07c5352

Happy to open a PR if that works for you.

Activity

  1. self-assigned this
    on Oct 19, 2026
  2. added a commit that references this issue on Oct 19, 2026
    0d8f539
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Fields

Priority

None yet

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions