Setting Array of Objects Type in TypeScript
TLDR Jameshwart asked how to set type of an array of objects in TypeScript. Jason advised them to use "object[]" and Typesense would infer the rest.
1
Jul 28, 2023 (4 months ago)
Jameshwart
02:17 AMJason
02:58 AMobject[]
Jameshwart
03:03 AMJason
03:30 AMJameshwart
03:32 AM[
{
"name": "simple",
"nameAndType": "simple|product_type",
"slug": "simple",
"type": "product_type",
"url": "https://google.com/?product_type=simple"
},
{
"name": "featured",
"nameAndType": "featured|product_visibility",
"slug": "featured",
"type": "product_visibility",
"url": "https://google.com/?product_visibility=featured"
},
{
"name": "Father's Day Gift Hampers",
"nameAndType": "Father's Day Gift Hampers|product_cat",
"slug": "fathers-day-gift-hampers",
"type": "product_cat",
"url": " "
}
]
this is the sample data Jason
Jason
03:36 AMobject[]
for the top level type, Typesense will infer the rest of the structure inside the nested array of objectsJason
03:37 AM{name: 'nestedField.slug', type: 'string[]', optional: true}
Jameshwart
03:39 AMJameshwart
03:39 AM1
Typesense
Indexed 3011 threads (79% resolved)
Similar Threads
Troubleshooting Typesense Collection with Nested Objects
Oskar was encountering problems in creating collections in Typesense with nested objects. Jason advised to ensure that the nested fields are defined as an array. Oskar was able to resolve the issue by rectifying the schema.
Adding and Storing Object Types in Typesense Collections
Abrar wanted help adding object types to a typesense collection, Sergio suggested flattening the object and Jason provided an approach to flatten objects and informed about upcoming version v0.24.0 with object support.
Using Typesense to Query by Custom Column Key Value
Sandip asked how to use Typesense to perform unique key searches in different organizations. Kishore Nallan suggested creating an 'object' field for varying keys. After a clarification, Sandip expressed satisfaction with the advice.
Configuring Typesense Extension for Nested Fields in Firebase Collection
David had issues indexing nested fields using the Typesense extension. Jason offered advice on specifying schemas and prioritizing specific fields, but there remained unresolved challenges with the schema.
Troubleshooting TypeScript Error with Typesense
GM experienced an error with Typesense in TypeScript, requiring help to correct the issues. Jason helped propose solutions and adjustments to the code. Ultimately, they were able to resolve the errors and successfully implement a search function.