😎 Discover cool tips and tricks for customization in our next Developer Deep Dive virtual event - sign up now!

Getting TypeScript definitions from defineType function in Sanity schema builder

6 replies
Last updated: Feb 25, 2023
Ahoj, is there a way to get a schema typescript definition from the 'defineType' function? I tried using whatever it returns but all I get is :
const environment: {
    type: "document";
    name: "environment";
} & Omit<DocumentDefinition, "preview"> & {
    preview?: PreviewConfig<{
        title: string;
        subheader: string;
        image: string;
    }, Record<"image" | "title" | "subheader", any>> | undefined;
}
There should be a slug and a bunch of other stuff on there?
πŸ€”
Feb 24, 2023, 7:14 PM
Ok I think this isnt a thing yet.This looks promising though, anyone had any success with it?

https://github.com/saiichihashimoto/sanity-typed-schema-builder
Feb 24, 2023, 7:28 PM
are you looking to gen types based on your schema? https://www.sanity.io/plugins/sanity-codegen
Feb 24, 2023, 8:30 PM
or are you trying to get types from sanity https://www.npmjs.com/package/@sanity/types
Feb 24, 2023, 8:30 PM
The former! I assumed the defineType function would also build a type to reuse elsewhere. I'll give the codegen a go! Cheers
Feb 24, 2023, 8:43 PM
Feb 25, 2023, 10:17 AM

Sanity– build remarkable experiences at scale

Sanity is a modern headless CMS that treats content as data to power your digital business. Free to get started, and pay-as-you-go on all plans.

Was this answer helpful?