Open flevi29 opened 1 year ago
Oh never mind found out why, should've researched a bit more. https://typesense.org/docs/0.24.0/api/collections.html#cloning-a-collection-schema
But then I guess the question becomes: Is there any point of providing anything else than the name of the new collection in this case? Or do the properties outside of name
override the copied schema ones? I just tested it and it really does seem that only thing that matters is the new name
, the rest is ignored.
In that case maybe making fields
required again and rewriting create
something like this might make more sense:
async create<TOptions extends CollectionCreateOptions>(
schema: TOptions["src_name"] extends string
? Pick<CollectionCreateSchema, "name">
: CollectionCreateSchema,
options?: TOptions,
): Promise<CollectionSchema> {
return this.apiCall.post<CollectionSchema>(RESOURCEPATH, schema, options);
}
@flevi29
I just tested it and it really does seem that only thing that matters is the new name, the rest is ignored.
That's correct. When src_name
is provided, all other fields are ignored.
I like the change you've proposed. Do you mind submitting it as a PR?
Why did
fields
become optional? Can you create a collection without it in some specific way?https://github.com/typesense/typesense-js/blob/c0d2abf17d4f9cda28ba8bf347d338b56a538780/src/Typesense/Collections.ts#L4-L11