#community-help

Auto-generating Typesense Collection Types with TypeScript

TLDR Udo asked about auto-generating types using schema definitions in Typesense. Jason clarified the limitations and suggested defining types manually. Udo agreed to add TypeScript notes to README.

Powered by Struct AI

1

1

7
7mo
Solved
Join the chat
Mar 21, 2023 (7 months ago)
Udo
Photo of md5-cabbd7b73bbc9bdf14391445a8d5890c
Udo
09:22 AM
to clarify, I did manage to create custom types that I can pass into collections (collections<SomethingType>('something')) but I was hoping there would be some sort of way to auto-generate these from the schema definition
Kishore Nallan
Photo of md5-4e872368b2b2668460205b409e95c2ea
Kishore Nallan
09:37 AM
cc Jason
Jason
Photo of md5-8813087cccc512313602b6d9f9ece19f
Jason
03:35 PM
Udo The collection schema type that Typesense uses has metadata fields in it, that your document will not have. Also the Typesense schema can also change dynamically on the Typesense server side. This is why itโ€™s hard to rely on the collection schema to generate the type for your document

1

03:36
Jason
03:36 PM
In any case, the assumption is that you already have a type defined for your document, and you can pass that into the Typesense library like youโ€™ve mentioned above
Udo
Photo of md5-cabbd7b73bbc9bdf14391445a8d5890c
Udo
04:10 PM
Jason thanks for clarifying. I guess I'm just spoiled from using prisma ๐Ÿ˜‰ I understand it's not the same thing and has some caveats...The lack of documentation just made me doubt if I'm missing something here. A short note about working with typescript in the README would be very helpful for newcomers
Jason
Photo of md5-8813087cccc512313602b6d9f9ece19f
Jason
04:11 PM
Iโ€™m not a Typescript expert myself, so if you want to add a note to the README in a PR about how to use with Typescript, that would be awesome!
Udo
Photo of md5-cabbd7b73bbc9bdf14391445a8d5890c
Udo
04:11 PM
sure thing

1