diff --git a/npm-packages/convex/src/server/database.ts b/npm-packages/convex/src/server/database.ts index 8ef32a565..fb047c436 100644 --- a/npm-packages/convex/src/server/database.ts +++ b/npm-packages/convex/src/server/database.ts @@ -191,7 +191,7 @@ export interface GenericDatabaseWriter patch>( table: NonUnion, id: GenericId, - value: Partial>, + value: PatchValue>, ): Promise; /** @@ -207,7 +207,7 @@ export interface GenericDatabaseWriter */ patch>( id: GenericId, - value: Partial>, + value: PatchValue>, ): Promise; /** @@ -311,7 +311,7 @@ export interface BaseTableWriter< */ patch( id: GenericId, - value: Partial>, + value: PatchValue>, ): Promise; /** @@ -341,3 +341,11 @@ export interface BaseTableWriter< type NonUnion = T extends never // `never` is the bottom type for TypeScript unions ? never : T; + +/** + * This is like Partial, but it also allows undefined to be passed to optional + * fields when `exactOptionalPropertyTypes` is enabled in the tsconfig. + */ +type PatchValue = { + [P in keyof T]?: undefined extends T[P] ? T[P] | undefined : T[P]; +};