sanity-typed-schema-builder
sanity-typed-schema-builder copied to clipboard
Type preview.component
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
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
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,
},