#Typescript doc

1 messages · Page 1 of 1 (latest)

woven mango
#

How can I type a Document for a table in typescript react native?

surreal tokenBOT
#

Hi @woven mango. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave:

#

To type a document for a table in TypeScript (including React Native), you should use the generated Doc<"tableName"> type from your Convex project's convex/_generated/dataModel. This type is automatically created based on your schema and provides end-to-end type safety for your documents.

Here's how you can use it:

import { Doc } from "../convex/_generated/dataModel";

function MyComponent(props: { message: Doc<"messages"> }) {
  // Now `props.message` is fully typed according to your schema
  // ...
}

This approach works the same way in React Native as it does in React for the web. Just make sure your Convex schema is defined and you've run npx convex dev to generate the type definitions. You can use these types throughout your client codebase to ensure type safety when working with Convex documents TypeScript types in schemas Writing frontend code in TypeScript.

Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: