ricokahler / sanity-codegen

Generate TypeScript types from your Sanity.io schemas
sanity-codegen-dev.vercel.app
MIT License
270 stars 19 forks source link

Objects in array are missing _type and _key #236

Closed piotrski closed 11 months ago

piotrski commented 2 years ago

Schema:

{
  name: 'content',
  type: 'array',
  title: 'Content',
  of: [
    {
      type: 'youtube',
    },
    {
      name: 'productSection',
      type: 'productSection',
      title: 'Products',
    }
  ]
}

Data:

content: [
  {
    "_key": "9d0a582dd846"
    "_type": "youtube"
    "url": "..."
  },
  {
    "_key": "c4c84d3114c9"
    "_type": "productSection"
    "products": [...] 1 item "title": "Prodct module"
  }
]

Type:

{
    content: Ref_9GdYNyKK3JQZWeEb | Ref_rxXogl98csCHdj1D
}
type Ref_9GdYNyKK3JQZWeEb = {
      _key: string; // it's missing
      _type: "youtube"; // missing
      url?: string;
      videoLabel?: string;
};

type Ref_rxXogl98csCHdj1D =
  | {
      _key: string; // it's missing
      _type: "productSection" // missing
      products?: Ref_xVWTU39k4Au07eM0[];
      title?: string;
    }[]
  | null;

This might be related to https://github.com/ricokahler/sanity-codegen/issues/85 I'm using groq-codegen v1.0.0-alpha.25

HuyAms commented 2 years ago

I face up with the same issue with reference type missing _type and _key. Any walkaround?

bertwillekens commented 2 years ago

I also need access to the _key property in my models.