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

How do deref() typings work in groqd > 1.0.0? #317

Open
2 tasks done
acnebs opened this issue Jan 7, 2025 · 0 comments
Open
2 tasks done

How do deref() typings work in groqd > 1.0.0? #317

acnebs opened this issue Jan 7, 2025 · 0 comments

Comments

@acnebs
Copy link

acnebs commented Jan 7, 2025

Is there an existing issue for this?

  • I have searched the existing issues

Code of Conduct

  • I agree to follow this project's Code of Conduct

Question

Hey, I've just started using groqd after the 1.0.0 release due to support for typed schemas. Great work, loving it so far.

However one issue I've run into is the typing of expanded (deref()) references. From the example below, I'd expect benefits to be an array of benefits according to Typescript, but it is actually still just an array of references. The actual query works fine though, returning the expanded references for my use. It is only a typing issue.

const landing = await runQuery(
    q.star
        .filterByType("landing")
        .project((sub) => ({
            "...": true,
            benefits: sub.field("benefits[]").deref(),
        }))
        .slice(0),
)

landing.benefits.map((benefit) => {
  // title is there and logs fine, but this throws a type error
  // typescript still thinks this is just reference and doesn't know about "title"
  console.log(benefit.title) 
})

Am I doing something wrong or is this a bug? The documentation for 1.0.0 is still a little sparse so I wasn't sure.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant