Just some Typescript tips: This method should not ...
# community-help
f
Just some Typescript tips: This method should not try to delete and retrieve and upsert documents into it, violating the Single Responsibility Principle. I'd break down the retrieve and delete to a method called
deleteIfExists
. Also, I'd avoid using so many
any
type defs, I'd probably use a Generic for data, and use it in the
batchData
Generic slot. Also, I'd use the
CollectionCreateSchema
specified in here
Copy code
export interface CollectionCreateSchema {
  name: string;
  default_sorting_field?: string;
  fields?: CollectionFieldSchema[];
  symbols_to_index?: string[];
  token_separators?: string[];
  enable_nested_fields?: boolean;
  metadata?: object;
  voice_query_model?: {
    model_name?: string;
  };
}
for the
schema
type. Finally, maybe pass the batch size as an argument to the function, instead of hard coding it? And maybe use
Array.prototype.forEach
instead of the
for...of
iterator? Just a personal preference at this point. Not really a Typesense specific problem, rather than some Typescript points
🙌 1