ricokahler / sanity-codegen

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

Allow two generated types to be the same #328

Open rohvald opened 9 months ago

rohvald commented 9 months ago

The following two schemas should generate two separate types, even though they would be identical.

Why? Because they might not be identical anymore in 10 minutes, and having us figure out one is omitted from generation only because they both have the same exact fields at the moment is awful. Took me 2+ hours to figure out what is going on.

I'd love to use Sanity if TS support was better.

import { defineType, defineField } from "sanity"

export default defineType({
  name: 'gearSection',
  title: 'Gear Section',
  type: 'object',
  fields: [
    defineField({
      name: 'title',
      title: 'Title',
      type: 'string',
      validation: (Rule) => Rule.required(),
    }),
    defineField({
      name: 'subtitle',
      title: 'Subtitle',
      type: 'string',
      validation: (Rule) => Rule.required(),
    })
  ]
})
import { defineType, defineField } from "sanity"

export default defineType({
  name: 'newArrivalsSection',
  title: 'New Arrivals Section',
  type: 'object',
  fields: [
    defineField({
      name: 'title',
      title: 'Title',
      type: 'string',
      validation: (Rule) => Rule.required(),
    }),
    defineField({
      name: 'subtitle',
      title: 'Subtitle',
      type: 'string',
      validation: (Rule) => Rule.required(),
    })
  ]
})