groqd icon indicating copy to clipboard operation
groqd copied to clipboard

Typescript complaining about inferred types when splitting queries

Open heggemsnes opened this issue 2 years ago • 4 comments

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,

heggemsnes avatar Feb 07 '23 08:02 heggemsnes

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.

heggemsnes avatar May 16 '23 12:05 heggemsnes

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.

TS Playground

yss14 avatar Aug 23 '23 13:08 yss14

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.

kevindice avatar Sep 07 '23 19:09 kevindice

Maintainer reproduction infertype

carbonrobot avatar Oct 30 '23 18:10 carbonrobot