groqd
groqd copied to clipboard
Typescript complaining about inferred types when splitting queries
Hi!
I get some weird errors when splitting queries into multiple files:
// step-one.query.ts
import { q } from "groqd"
export const stepOneQuery = q("stepOne").grab({
title: q.string(),
})
This returns the error:
The inferred type of this node exceeds the maximum length the compiler will serialize. An explicit type annotation is needed
Of course explicitly typing the query kinda ruins the point heh.
Adding this to mu tsconfig.json file removes the error:
"declaration": false,
"declarationMap": false,
As we've been using groqd more and more this shows up basically when the queries/types become very large.
I'm pretty sure this probably isn't something groqd can fix directly, but doing:
const pageQuery = /* huge page query with a page builder or something */
type PageType = inferType<typeof pageQuery>
Would be pretty awesome.
For us even the most simple groqd query results in this issue, which makes the library unusable, since we cannot inline all the queries.
Disabling declaration emit is also no option, since we are using composite projects.
We're seeing this issue too. The problem only occurs when we try to export type the type returned from InferType.
We have a monorepo and disabling "declaration": true, is likely a non-starter for us too. This error is distinct from the "excessively deep and possibly infinite" error, so my impression is that the type is indeed finite - just that it exceeds what TS is willing to serialize into a .d.ts file.
I see similar issues on the underlying Zod GH project - one person suggested a hacky yarn patch to increase the TS serialization length limit.
Maintainer reproduction