![](https://cdn.discordapp.com/avatars/671883691747835939/56b1aa0560a6c14a6a0e0487b53448dd.webp)
can we extend Document
to infer types of attributes while retrieving documents on Typescript? What's the preferred way? Because DocumentList<Document>
doesn't include attributes and currently I have to go with any as workaround.
![](https://cdn.discordapp.com/avatars/831428608895615056/339f3421956eaa960eefbea11d58e0bb.webp)
what's the usecase?
iirc, the main structure would be in Document.data
, DocumentList
is just a type that holds a total: number
& the list of documents
. If you mean infer the return type from the sdk return types, I don't think so.
![](https://cdn.discordapp.com/avatars/831428608895615056/339f3421956eaa960eefbea11d58e0bb.webp)
you can always play around with extended types though.
![](https://cdn.discordapp.com/avatars/831428608895615056/339f3421956eaa960eefbea11d58e0bb.webp)
you could do some sort of documents.map((doc) => ...)
.
![](https://cdn.discordapp.com/embed/avatars/0.png)
From what I understand, instead of doing document.data["Attribute"] Doing document.data.attribute so it gets completed automatically
![](https://cdn.discordapp.com/avatars/831428608895615056/339f3421956eaa960eefbea11d58e0bb.webp)
i see, but the type won't exist due to data
's dynamic nature. but iirc, there was a library by a community member that would pre-fetch the types. should be in #🛠│tools ig.
![](https://cdn.discordapp.com/avatars/671883691747835939/56b1aa0560a6c14a6a0e0487b53448dd.webp)
Maybe I didn't explained it well enough. Could be something totally related to ts only. Let me give bit more context. Give me a while
![](https://cdn.discordapp.com/avatars/671883691747835939/56b1aa0560a6c14a6a0e0487b53448dd.webp)
Following is a function I'm using to retrieve some aatribute from the documents.
const statsData = await databases.listDocuments(
APPWRITE_DB_ID,
APPWRITE_FILES_COUNTS_COL_ID,
[Query.select(["year", "month", "count"])]
);
The return type right now is statsData
is Models.DocumentList<Models.Document>
. The Models.Document
type has metadata related values mostly. like $id
, $createdAt
Can I extend the type of Document
such that along with the metadata, I can also get type of the attributes I've queried with Query.select()
?
Along with the existing Document
type, I also want to infer following when I access statsData
interface Stat {
year: number,
month: number,
count: number
}
![](https://cdn.discordapp.com/avatars/671883691747835939/56b1aa0560a6c14a6a0e0487b53448dd.webp)
@Darshan Pandya @D5
Recommended threads
- chunked upload not working anymore - Ap...
Hi, I’m experiencing an issue with** chunked uploads** after upgrading the** Appwrite Web SDK** from **14.0.0** to **17.0.0**. In version **14.0.0**, I impleme...
- Status "stuck" after trying to delete a ...
Hi, I tried first to re-name a two-way relation field between two collections, when I received an error tried to delete two fields. Deleted all the data rows, ...
- Database not found - error
register.ts: ```import { Elysia, t } from 'elysia'; import { account, databases, users } from '../../appwrite manager/appwrite'; import { ID } from 'appwrite'; ...
![](/images/bgs/pre-footer.png)