Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Typescript complaining about inferred types when splitting queries #58

Open
heggemsnes opened this issue Feb 7, 2023 · 4 comments
Open
Labels
bug Something isn't working

Comments

@heggemsnes
Copy link
Contributor

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
Copy link
Contributor Author

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.

@yss14
Copy link

yss14 commented Aug 23, 2023

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

@kevindice
Copy link

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.

@carbonrobot carbonrobot added the bug Something isn't working label Oct 30, 2023
@carbonrobot
Copy link
Contributor

Maintainer reproduction
infertype

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants