#Can I access the type of of an item in a document?
1 messages · Page 1 of 1 (latest)
Hi @proven hazel. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave:
Yes, you can access the type of a property of a document in Convex using TypeScript's indexed access types. Once you have the generated Doc<"invoices"> type, you can get the type of the lineItems property like this:
import { Doc } from "../convex/_generated/dataModel";
type LineItems = Doc<"invoices">["lineItems"];
This will give you the exact type of the lineItems property as defined in your schema. This approach works for any property of a document type generated by Convex. If you need the type of an item within an array property (e.g., if lineItems is an array), you can use:
type LineItem = Doc<"invoices">["lineItems"][number];
This extracts the type of a single item in the lineItems array.