-
Notifications
You must be signed in to change notification settings - Fork 0
Description
Describe the bug
Sanity typegen generates incorrect TypeScript types when using the rest operator (...) inside an array projection in GROQ.
The GROQ query itself works correctly at runtime, but the generated types do not match the actual returned data, which breaks TypeScript typings downstream.
To Reproduce
GROQ query using rest operator inside array projection:
*[_type == "page"]{
pageContent[] {
...,
},
}
Running sanity typegen generate produces incorrect or incomplete types for pageContent.
{
pageContent: Array<unknown> | null;
}Expected behavior
The generated TypeScript types for pageContent should be identical to the ones produced when using a direct array projection, since the query results are equivalent.
Working version:
*[_type == "page"]{
pageContent[],
}
And the types that should be generated from this query:
{
pageContent: Array<{
_key: string;
} & Cta | {
_key: string;
} & Explanation | {
_key: string;
} & Hero | {
_key: string;
} & Holders | {
_key: string;
} & PageText> | null;
}Actual behavior
The query using { ... } inside the array causes typegen to:
- generate incorrect field types
- lose discriminated union information, or produce overly generic / broken typings for array items
This results in type errors in consuming code despite the query being valid and working at runtime.
Which versions of Sanity are you using?
@sanity/cli (global) 5.8.1 (up to date)
@sanity/ui 3.1.11 (up to date)
@sanity/vision 5.8.1 (up to date)
sanity 5.8.1 (up to date)Which versions of Node.js / npm are you running?
npm: 11.6.2
Node: v24.13.0