sanity-io / sanity-plugin-mux-input

An input component that integrates Sanity Studio with MUX.com video encoding/hosting service.
https://mux.com
MIT License
53 stars 56 forks source link

Incorrect Types Generated by Sanity TypeGen #371

Open r0skar opened 5 months ago

r0skar commented 5 months ago

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 commented 2 months ago

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

ivyrze commented 2 months ago

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

heggemsnes commented 2 weeks ago

Still happening as of Sanity 3.62.3

sgulseth commented 2 weeks ago

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.