Where to get type referenced
from?
#246
-
Hello @scottrippey, I'm trying I then run The import { createGroqBuilder, ExtractDocumentTypes } from 'groq-builder';
import { referenced, SanityValues } from './sanity-schema'; // This is the generated file but should be: import { createGroqBuilder } from 'groq-builder';
import type { ExtractDocumentTypes } from 'groq-builder';
import type { referenced, SanityValues } from './sanity-schema'; // This is the generated file Aside from the missing |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 6 replies
-
@ringods Thank you for trying it out! While this is in alpha stage, we're getting close to a beta, and having you try this out is really useful and helpful. I'd love to help with this issue. When the Sanity config contains any "reference" types, the generated types will include a special unique symbol called import { defineArrayMember, defineField, defineType } from "@sanity-typed/types";
export const Variant = defineType({
name: "variant",
type: "document",
fields: [
defineField({ name: "name", type: "string", }),
defineField({ name: "price", type: "number", }),
defineField({
name: "flavours",
title: "Flavours",
type: "array",
of: [
defineArrayMember({
type: "reference",
to: [{ type: "flavour" } as const],
}),
],
}),
],
}); Notice the After running export declare const referenced: unique symbol;
export type SanityValues = {
variant: {
_type: "variant";
_id: string;
name: string;
price: number;
flavours: {
_type: "reference";
[referenced]: "flavour";
_ref: string;
_key: string;
}[];
};
}; Notice how the So, hopefully that explains what to expect. Can you please let me know what you're seeing instead? |
Beta Was this translation helpful? Give feedback.
@ringods Thank you for trying it out! While this is in alpha stage, we're getting close to a beta, and having you try this out is really useful and helpful. I'd love to help with this issue.
When the Sanity config contains any "reference" types, the generated types will include a special unique symbol called
referenced
. For example, here's an abbreviatedVariant
document definition: