Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CollectionCreateSchema fields property is now optional in types #149

Open
flevi29 opened this issue Feb 11, 2023 · 2 comments
Open

CollectionCreateSchema fields property is now optional in types #149

flevi29 opened this issue Feb 11, 2023 · 2 comments

Comments

@flevi29
Copy link

flevi29 commented Feb 11, 2023

Why did fields become optional? Can you create a collection without it in some specific way?

export interface CollectionCreateSchema {
name: string
default_sorting_field?: string
fields?: CollectionFieldSchema[]
symbols_to_index?: string[]
token_separators?: string[]
enable_nested_fields?: boolean
}

@flevi29
Copy link
Author

flevi29 commented Feb 11, 2023

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);
  }

@jasonbosco
Copy link
Member

@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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants