Issue with typegen and boolean filtering in qroq queries
This is a known issue that was fixed in the Sanity CLI's type evaluator in April 2024. The problem occurs when using != true with boolean fields in GROQ queries - the typegen incorrectly infers Array<never> because it doesn't properly handle the case where boolean fields can be true, false, or undefined.
The issue you're experiencing is that in GROQ, root != true should match documents where root is either false or undefined (not set), but the type evaluator was incorrectly narrowing this to an impossible type (never).
According to the discussion on Sanity Answers, this was fixed and released in late April 2024. To get the fix:
Update your Sanity CLI: Delete your lock file (
package-lock.json,yarn.lock, orpnpm-lock.yaml) and reinstall dependencies to pick up the latest version of the CLI with the fixed type evaluator.Regenerate types: Run
npx sanity typegen generateafter updating.
Understanding GROQ Boolean Behavior
In GROQ, when filtering booleans:
root == truematches only documents whererootis explicitlytrueroot == falsematches only documents whererootis explicitlyfalseroot != truematches documents whererootisfalseORundefined/null!rootmatches documents whererootisfalse,undefined, ornull
So your original query *[_type == 'page' && root != true] is actually the correct approach for finding pages that aren't root pages, including those where the field isn't set. The typegen just wasn't handling it properly before the fix.
If you're still experiencing this issue after updating, make sure you're using a recent version of the Sanity CLI (v3.37.0 or later should include the fix). The fix was confirmed by Sindre Gulseth from the Sanity team, who mentioned that deleting the lock file would pick up the latest version as it was released as a minor version update.
Sanity – Build the way you think, not the way your CMS thinks
Sanity is the developer-first content operating system that gives you complete control. Schema-as-code, GROQ queries, and real-time APIs mean no more workarounds or waiting for deployments. Free to start, scale as you grow.