From b4e749ea031ece37db59e2d87e39504a48e08011 Mon Sep 17 00:00:00 2001 From: David Plugge Date: Tue, 6 Feb 2024 09:49:32 +0100 Subject: [PATCH] correctly type empty select --- .changeset/brave-rabbits-scream.md | 5 +++++ src/client.ts | 16 ++++++++-------- src/select.ts | 5 ++--- 3 files changed, 15 insertions(+), 11 deletions(-) create mode 100644 .changeset/brave-rabbits-scream.md diff --git a/.changeset/brave-rabbits-scream.md b/.changeset/brave-rabbits-scream.md new file mode 100644 index 0000000..d4164bd --- /dev/null +++ b/.changeset/brave-rabbits-scream.md @@ -0,0 +1,5 @@ +--- +"typed-pocketbase": patch +--- + +correctly type empty select diff --git a/src/client.ts b/src/client.ts index 40e29fc..318a0db 100644 --- a/src/client.ts +++ b/src/client.ts @@ -51,7 +51,7 @@ export interface ViewCollectionService< filter?: Filter; } & SendOptions ): Promise[]>; - getList>( + getList = {}>( page?: number, perPage?: number, options?: { @@ -60,14 +60,14 @@ export interface ViewCollectionService< filter?: Filter; } & SendOptions ): Promise>>; - getFirstListItem>( + getFirstListItem = {}>( filter: Filter, options?: { select?: TSelect; sort?: MaybeArray>; } & SendOptions ): Promise>; - getOne>( + getOne = {}>( id: string, options?: { select?: TSelect; @@ -83,13 +83,13 @@ export interface ViewCollectionService< export interface BaseCollectionService extends ViewCollectionService { - create>( + create = {}>( bodyParams: Collection['create'], options?: { select?: TSelect; } & SendOptions ): Promise>; - update>( + update = {}>( id: string, bodyParams: Collection['update'], options?: { @@ -102,7 +102,7 @@ export interface BaseCollectionService export interface AuthCollectionService extends BaseCollectionService, Pick { - authWithPassword>( + authWithPassword = {}>( usernameOrEmail: string, password: string, options?: { @@ -111,7 +111,7 @@ export interface AuthCollectionService ): Promise< RecordAuthResponse> >; - authWithOAuth2Code>( + authWithOAuth2Code = {}>( provider: string, code: string, codeVerifier: string, @@ -130,7 +130,7 @@ export interface AuthCollectionService createData?: Collection['create']; } & SendOptions ): Promise>; - authRefresh>( + authRefresh = {}>( options?: { select?: TSelect; } & SendOptions diff --git a/src/select.ts b/src/select.ts index de6c846..2c9b1f3 100644 --- a/src/select.ts +++ b/src/select.ts @@ -21,9 +21,8 @@ export type SelectWithExpand = export type ResolveSelect< TCollection extends GenericCollection, TSelect extends Select | undefined -> = undefined extends TSelect - ? TCollection['response'] - : Extract extends never +> = + Extract extends never ? TCollection['response'] : { [K in keyof TSelect &