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

Incorrect Types Generated by Sanity TypeGen #371

Open
r0skar opened this issue Jun 18, 2024 · 4 comments
Open

Incorrect Types Generated by Sanity TypeGen #371

r0skar opened this issue Jun 18, 2024 · 4 comments

Comments

@r0skar
Copy link

r0skar commented Jun 18, 2024

Describe the bug

Using sanity-typegen to create GROQ query types results in wrong types.

To Reproduce

Steps to reproduce the behavior:

  1. Add the plugin, create and use it in a field.
  2. Query the field:
  const videoBlockQ = groq`*[_type == "blockVideo" && _id == $blockId][0]{
    _id,
    _type,
    title,
    video{
      asset->{
        playbackId,
        assetId,
        filename,
      }
    }
  }`;
  1. Run typegen:
// Query: *[_type == "blockVideo" && _id == $blockId][0]{    _id,    _type,    title,    video{      asset->{        playbackId,        assetId,        filename,      }    }  }
export type VideoBlockQResult = {
  _id: string;
  _type: "blockVideo";
  title: string | undefined;
  video: {
    asset: null;
  } | undefined;
} | undefined;

Expected behavior

VideoBlockQResult["video"]["asset"] should be of type Partial<MuxVideoAsset> | undefined

Which versions of Sanity are you using?

Run sanity versions in the terminal and copy-paste the result here.

@sanity/cli (global)  3.46.1 (up to date)
@sanity/image-url      1.0.2 (up to date)
sanity                3.46.1 (up to date)

What operating system are you using?

Linux 6.9.4-arch1-1

Which versions of Node.js / npm are you running?

20.9.0
@sgulseth
Copy link
Member

sgulseth commented Sep 2, 2024

@r0skar can you still reproduce this with the latest version of sanity?

@ivyrze
Copy link

ivyrze commented Sep 5, 2024

@sgulseth Not the OP but I'm still experiencing this on the latest version (3.57.0).

@heggemsnes
Copy link

Still happening as of Sanity 3.62.3

@sgulseth
Copy link
Member

Thanks for the update, and sorry the delay here. I think this is because of a conflicting type name when we serialize the type names to be compatible as a TS identifier.

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

4 participants