GetPayload utility types should accept readonly (as const) include shapes
维护者通常 1 天内回复
还没有人认领这个 Issue。
评估
- 难度
- 4/5
- 预计耗时
- 3-5 天
- 新手友好度
- 25/100
- Issue 类型
- 功能
- 描述清晰度
- 基本清楚
- 活跃度
- 冷清
- 技术栈
- typescript
- 领域
- backend
调研方向
Start from the $SelectIncludeOmit constraint and the generated ModelGetPayload<Args> utility type named in the issue; the fix relaxes that constraint (or the payload computation consuming it) so readonly arrays and properties from as const are accepted. Reproduce with the 6-level postInclude snippet and a type-level assertion that PostGetPayload<{ include: ReturnType<typeof postInclude> }> resolves without DeepMutable. Done when that typecheck test passes and existing payload type tests still hold.
由索引模型根据 Issue 内容生成。
描述
Description and expected behavior
When a findUnique/findMany query uses deeply nested include (6+ levels), TypeScript's inference depth limit causes the return type to collapse to any. The recommended workaround is to use the generated ModelGetPayload<Args> utility type to compute the payload type at the type level, bypassing inference.
However, to preserve literal true values (required for GetPayload to resolve which relations are included), the include object must use as const. This produces readonly types, which are rejected by GetPayload's constraint ($SelectIncludeOmit).
A query 6+ levels deep:
function postInclude(postId: string) {
return {
author: true,
sections: {
include: {
blocks: {
where: { type: { in: [BlockType.TEXT, BlockType.IMAGE] } },
include: {
comments: { where: { postId } },
revisions: {
orderBy: { createdAt: "asc" },
include: {
changes: {
include: {
annotations: { include: { tag: true } },
},
},
},
},
},
},
},
},
} as const;
}
Current workaround
Users must define a recursive DeepMutable utility type to strip readonly before passing to GetPayload:
type DeepMutable<T> =
T extends ReadonlyArray<infer U>
? DeepMutable<U>[]
: T extends object
? { -readonly [K in keyof T]: DeepMutable<T[K]> }
: T;
// ❌ Fails: readonly types from `as const` don't satisfy $SelectIncludeOmit
type Broken = PostGetPayload<{ include: ReturnType<typeof postInclude> }>;
// ✅ Works but requires boilerplate DeepMutable
type FullPost = NonNullable<
PostGetPayload<DeepMutable<{ include: ReturnType<typeof postInclude> }>>
>;
Additionally, the findUnique call itself requires @ts-expect-error because the deeply nested include also fails inference at the call site, and an explicit return type annotation is needed:
async function fetchPost(
postId: string,
db: ZenDb,
): Promise<FullPost | null> {
// @ts-expect-error -- findUnique inference hits TS depth limit on deeply nested includes
return db.post.findUnique({
where: { id: postId },
include: postInclude(postId),
});
}
// Downstream types now resolve correctly
type Section = FullPost["sections"][number];
type Block = Section["blocks"][number];
type Revision = Block["revisions"][number];
type Change = Revision["changes"][number];
type Annotation = Change["annotations"][number];
Expected behaviour
GetPayload should accept readonly include shapes natively:
// Should just work — no DeepMutable needed
type FullPost = NonNullable<
PostGetPayload<{ include: ReturnType<typeof postInclude> }>
>;
Environment (please complete the following information):
- ZenStack version: 3.7.2
- Database type: Postgresql
- Node.js version: 24x
- Package manager: npm
Additional context
Context
This pattern is needed when:
Schema has deeply nested relations (6+ levels: Post → Section → Block → Revision → Change → Annotation → Tag)
Users want to extract typed helpers from query results (e.g., type Block = FullPost["sections"][number]["blocks"][number]
The ReturnType approach silently resolves to any due to TS depth limits
- 主要语言
- TypeScript
- 星标
- 2.9k
- 派生
- 157
- 平均合并
- 11 小时 42 分钟
- 30 天内合并 PR
- 20
环境准备
这个项目没有提供开发容器、Dockerfile 或贡献指南,环境需要你自己搭建:先看它的 README,通用步骤见我们的新手贡献指南。
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
zenstackhq/zenstack 的其他 Issue
-
难度 2/5 1-3 小时 新手友好度 68/100
zenstackhq/zenstack#2873 ·
维护者通常 1 天内回复
-
runtime
难度 2/5 1-3 小时 新手友好度 78/100
zenstackhq/zenstack#2868 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 72/100
zenstackhq/zenstack#2694 · 3 条评论 ·
维护者通常 1 天内回复
-
难度 1/5 1 小时以内 新手友好度 68/100
zenstackhq/zenstack#2659 · 2 条评论 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 65/100
zenstackhq/zenstack#2542 · 1 条评论 ·
维护者通常 1 天内回复
查看 zenstackhq/zenstack 的全部 Issue
相似的 Issue
-
community first-timers-only good first issue hacktoberfest help wanted low hanging fruit up-for-grabs
难度 1/5 1 小时以内 新手友好度 75/100
lingdojo/kana-dojo#32018 · 1 条评论 · 5 个 reaction ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 72/100
paperclipai/paperclip#15751 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 72/100
BuilderIO/agent-native#7275 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 74/100
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 65/100
维护者通常 1 天内回复