From b46b5ab5c690bd5d937827fe54544db38ef02150 Mon Sep 17 00:00:00 2001 From: Christopher Pruijsen Date: Wed, 7 Oct 2026 21:44:58 +0100 Subject: [PATCH 1/2] fix(collection): return the partial update schema from Collection.update --- src/Typesense/Collection.ts | 9 +++++++-- test/collection-update.type.test.ts | 20 ++++++++++++++++++++ 2 files changed, 27 insertions(+), 2 deletions(-) create mode 100644 test/collection-update.type.test.ts diff --git a/src/Typesense/Collection.ts b/src/Typesense/Collection.ts index 9bedd832..47c68c82 100644 --- a/src/Typesense/Collection.ts +++ b/src/Typesense/Collection.ts @@ -101,8 +101,13 @@ export default class Collection { return this.apiCall.get(this.endpointPath()); } - async update(schema: CollectionUpdateSchema): Promise { - return this.apiCall.patch(this.endpointPath(), schema); + async update( + schema: CollectionUpdateSchema, + ): Promise { + return this.apiCall.patch( + this.endpointPath(), + schema, + ); } async delete( diff --git a/test/collection-update.type.test.ts b/test/collection-update.type.test.ts new file mode 100644 index 00000000..084c95c3 --- /dev/null +++ b/test/collection-update.type.test.ts @@ -0,0 +1,20 @@ +import { describe, expectTypeOf, it } from "vitest"; +import type Collection from "../src/Typesense/Collection"; +import type { + CollectionSchema, + CollectionUpdateSchema, +} from "../src/Typesense/Collection"; + +describe("collection update", () => { + it("resolves to the collection update schema", () => { + expectTypeOf>().toEqualTypeOf< + Promise + >(); + }); + + it("does not resolve to the full collection schema", () => { + expectTypeOf>().not.toEqualTypeOf< + Promise + >(); + }); +}); From f20616919c61be65af3d58334e40b915c856576c Mon Sep 17 00:00:00 2001 From: Christopher Pruijsen Date: Sat, 10 Oct 2026 11:27:26 +0100 Subject: [PATCH 2/2] test(collection): move update return-type test into Collection.spec.ts --- test/Typesense/Collection.spec.ts | 22 +++++++++++++++++----- test/collection-update.type.test.ts | 20 -------------------- 2 files changed, 17 insertions(+), 25 deletions(-) delete mode 100644 test/collection-update.type.test.ts diff --git a/test/Typesense/Collection.spec.ts b/test/Typesense/Collection.spec.ts index 4cb9487c..a63d2b66 100644 --- a/test/Typesense/Collection.spec.ts +++ b/test/Typesense/Collection.spec.ts @@ -1,5 +1,13 @@ -import { describe, it, expect, beforeEach, afterEach } from "vitest"; +import { + describe, + it, + expect, + expectTypeOf, + beforeEach, + afterEach, +} from "vitest"; import { Client as TypesenseClient } from "../../src/Typesense"; +import type { CollectionUpdateSchema } from "../../src/Typesense/Collection"; import { ObjectNotFound } from "../../src/Typesense/Errors"; describe("Collection", function () { @@ -108,12 +116,16 @@ describe("Collection", function () { fields: [{ name: "new_field", type: "string" as const }], }; - const updateResult = await collection.update(updateSchema); + const typedCollection = typesense.collections(testCollectionName); + const updateResult = await typedCollection.update(updateSchema); + expectTypeOf(updateResult).toEqualTypeOf(); expect(updateResult).toBeDefined(); - expect(updateResult.fields).toHaveLength(1); - expect(updateResult.fields[0].name).toBe("new_field"); - expect(updateResult.fields[0].type).toBe("string"); + expect(updateResult).not.toHaveProperty("name"); + expect(updateResult).not.toHaveProperty("num_documents"); + expect(updateResult.fields).toMatchObject([ + { name: "new_field", type: "string" }, + ]); // Verify the update by retrieving the collection const updatedCollection = await collection.retrieve(); diff --git a/test/collection-update.type.test.ts b/test/collection-update.type.test.ts deleted file mode 100644 index 084c95c3..00000000 --- a/test/collection-update.type.test.ts +++ /dev/null @@ -1,20 +0,0 @@ -import { describe, expectTypeOf, it } from "vitest"; -import type Collection from "../src/Typesense/Collection"; -import type { - CollectionSchema, - CollectionUpdateSchema, -} from "../src/Typesense/Collection"; - -describe("collection update", () => { - it("resolves to the collection update schema", () => { - expectTypeOf>().toEqualTypeOf< - Promise - >(); - }); - - it("does not resolve to the full collection schema", () => { - expectTypeOf>().not.toEqualTypeOf< - Promise - >(); - }); -});