Hacktoberfest 2026:维护者为十月标记出来的 issue,仍然开放、适合新手。 浏览 Hacktoberfest issue

`InferProps` keeps `Promise` and `Response` for a `withValidator` loader

未关闭 适合新手
#478 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

还没有人认领这个 Issue。

评估

难度
2/5
预计耗时
1-3 小时
新手友好度
82/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
活跃
技术栈
typescript

调研方向

首先阅读 defineHandler.withValidator 的返回类型,以及 InferProps 如何读取 __output。为一个返回 { book } 或 Response 的 loader 添加类型测试,并检查 InferProps<typeof loader> 是否解析为 { book: Book },而不是 promise 或 response 的联合类型。

由索引模型根据 Issue 内容生成。

描述

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.

主要语言
TypeScript
星标
402
派生
32
平均合并
12 小时 28 分钟
30 天内合并 PR
77

环境准备

这个项目没有提供开发容器、Dockerfile 或贡献指南,环境需要你自己搭建:先看它的 README,通用步骤见我们的新手贡献指南。

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

voidzero-dev/void 的其他 Issue

查看 voidzero-dev/void 的全部 Issue

相似的 Issue

更多 TypeScript Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。