sanity-typed-schema-builder icon indicating copy to clipboard operation
sanity-typed-schema-builder copied to clipboard

Type preview.component

Open benjick opened this issue 2 years ago • 2 comments

Hello!

Thank you so much for this plugin!

I'm having some trouble with attaching a preview component to my objectNamed. In my old js code I just do it like this:

preview: {
  select: {
    title: "title",
    image: "image",
  },
  component: Preview,
},

but the preview.component key is not valid to use.

Cheers

benjick avatar Oct 30 '22 23:10 benjick

It was very difficult to type the props for component from the select, but it's doable! The work would have to happen in this file I believe: https://github.com/saiichihashimoto/sanity-typed-schema-builder/blob/master/src/field/index.ts#L125

saiichihashimoto avatar Oct 31 '22 20:10 saiichihashimoto

You can do this as a workaround, which will throw an error when the component preview support is implemented, at which point you can remove it and get proper validation.

preview: {
  select: {
    title: "title",
    image: "image",
  },
  // @ts-expect-error component is not yet supported in sanity-typed-schema-builder, but is passed on to Sanity
  component: Preview,
},

miklschmidt avatar Dec 13 '22 12:12 miklschmidt