Skip to content
Back

How to type the documents that come back using typescript

  • 0
  • Databases
  • Web
MB7
23 Oct, 2024, 12:43

Hello,

I was wondering the best way to strongly type using typescript the return type of listDocuments etc. Is the below correct or is there a better way to do this/generate types?

TypeScript
type Test = {
  name: string
} & Models.Document

const result = await databases.listDocuments<Test>()

result.documents[0].name

Thank you

TL;DR
Type the return of `databases.listDocuments` using TypeScript by creating a custom type union with `Models.Document`. Use the code snippet provided in the message to achieve this. Would you like to try using this tool for further assistance: https://discord.com/channels/564160730845151244/837593904952901634/1292063850371350560
MB7
23 Oct, 2024, 12:43

How to type the documents that come back using typescript

darShan
23 Oct, 2024, 12:55

There's currently no support for this but there's this tool if thats of any help (haven't tried personally though) - https://discord.com/channels/564160730845151244/837593904952901634/1292063850371350560

Reply

Reply to this thread by joining our Discord

Reply on Discord

Need support?

Join our Discord

Get community support by joining our Discord server.

Join Discord

Get premium support

Join Appwrite Pro and get email support from our team.

Learn more