Skip to content
\n

which is the best way to obtain metadata like $id?

","upvoteCount":1,"answerCount":1,"acceptedAnswer":{"@type":"Answer","text":"

Hi Maryusz,

\n

When using appwrite types to generate types, the tool primarily creates type definitions based on your database or API schemas, but it doesn’t automatically include metadata fields like $id in the generated types by default.

\n

To include metadata such as $id in your types, here are some approaches:

\n

Extend generated types manually:
\nAfter generating types, you can create your own TypeScript interfaces or types that extend the generated ones and add the $id field where needed. For example:

\n
import { GeneratedType } from './generated-types';\n\ninterface ExtendedType extends GeneratedType {\n  $id: string;\n}\n
\n

Check if your schema includes metadata:
\nSometimes, metadata fields like $id are part of the data returned by the API but not defined in your schema. You might need to update your schema definitions in Appwrite to explicitly include these fields so the generator picks them up.

\n

Use runtime typings:
\nIf metadata fields are dynamic or not part of your schema, consider handling them at runtime, e.g., by defining utility types or guards that accommodate such properties.

\n

Consult Appwrite documentation or feature requests:
\nThe CLI or generator might evolve, so keep an eye on Appwrite’s docs or GitHub issues for updates or flags that allow metadata inclusion.

","upvoteCount":2,"url":"https://github.com/appwrite/appwrite/discussions/10121#discussioncomment-13979935"}}}
Discussion options

You must be logged in to vote

Hi Maryusz,

When using appwrite types to generate types, the tool primarily creates type definitions based on your database or API schemas, but it doesn’t automatically include metadata fields like $id in the generated types by default.

To include metadata such as $id in your types, here are some approaches:

Extend generated types manually:
After generating types, you can create your own TypeScript interfaces or types that extend the generated ones and add the $id field where needed. For example:

import { GeneratedType } from './generated-types';

interface ExtendedType extends GeneratedType {
  $id: string;
}

Check if your schema includes metadata:
Sometimes, metadata fields like $id ar…

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by Maryusz
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants