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

Improve types for collection creation with src_name option #151

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions src/Typesense/Collections.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { CollectionFieldSchema, CollectionSchema } from './Collection'
export interface CollectionCreateSchema {
name: string
default_sorting_field?: string
fields?: CollectionFieldSchema[]
fields: CollectionFieldSchema[]
symbols_to_index?: string[]
token_separators?: string[]
enable_nested_fields?: boolean
Expand All @@ -19,7 +19,10 @@ const RESOURCEPATH = '/collections'
export default class Collections {
constructor(private apiCall: ApiCall) {}

async create(schema: CollectionCreateSchema, options: CollectionCreateOptions = {}): Promise<CollectionSchema> {
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)
}

Expand Down