`InferProps` keeps `Promise` and `Response` for a `withValidator` loader
Maintainers usually reply within 1 day
Nobody has claimed this yet.
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 82/100
- Issue type
- Bug
- Clarity
- Clearly specified
- Activity status
- Active
- Tech stack
- typescript
- Domain
- backend-api-design
Research direction
Start by reading the defineHandler.withValidator return type and how InferProps reads __output. Add a type test for a loader that returns { book } or a Response, and check that InferProps<typeof loader> resolves to { book: Book } rather than a promise or response union.
Written by the indexing model from the issue text.
Description
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: https://github.com/ashunar0/void/commit/07c5352d58f880a0c77b78ce38aa5fb6fc832d5f
Happy to open a PR if that works for you.
- Dominant language
- TypeScript
- Stars
- 402
- Forks
- 32
- Avg merge
- 12h 28m
- Merged PRs (30d)
- 77
Getting set up
This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from voidzero-dev/void
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
voidzero-dev/void#463 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
voidzero-dev/void#459 ·
Maintainers usually reply within 1 day
-
bug
Difficulty 1/5 1-3 hours Newbie friendliness 78/100
voidzero-dev/void#428 ·
Maintainers usually reply within 1 day
-
Difficulty 3/5 1-2 days Newbie friendliness 68/100
voidzero-dev/void#480 ·
Maintainers usually reply within 1 day
-
Difficulty 4/5 3-5 days Newbie friendliness 56/100
voidzero-dev/void#477 ·
Maintainers usually reply within 1 day
All issues in voidzero-dev/void
Similar issues
-
freshness freshness:observed-only
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
thoroc/context-radar#280 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 66/100
-
documentation story
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
Maintainers usually reply within 1 day
-
bug category:billing priority:p3 track:fast
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
LanternOps/breeze#9223 ·
Maintainers usually reply within 1 day