Skip to content

Commit

Permalink
correctly type empty select
Browse files Browse the repository at this point in the history
  • Loading branch information
david-plugge committed Feb 6, 2024
1 parent 129b8fd commit b4e749e
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 11 deletions.
5 changes: 5 additions & 0 deletions .changeset/brave-rabbits-scream.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"typed-pocketbase": patch
---

correctly type empty select
16 changes: 8 additions & 8 deletions src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ export interface ViewCollectionService<
filter?: Filter<ExpandedRecord>;
} & SendOptions
): Promise<ResolveSelectWithExpand<Collection, TSelect>[]>;
getList<TSelect extends SelectWithExpand<Collection>>(
getList<TSelect extends SelectWithExpand<Collection> = {}>(
page?: number,
perPage?: number,
options?: {
Expand All @@ -60,14 +60,14 @@ export interface ViewCollectionService<
filter?: Filter<ExpandedRecord>;
} & SendOptions
): Promise<ListResult<ResolveSelectWithExpand<Collection, TSelect>>>;
getFirstListItem<TSelect extends SelectWithExpand<Collection>>(
getFirstListItem<TSelect extends SelectWithExpand<Collection> = {}>(
filter: Filter<ExpandedRecord>,
options?: {
select?: TSelect;
sort?: MaybeArray<Sort<ExpandedRecord>>;
} & SendOptions
): Promise<ResolveSelectWithExpand<Collection, TSelect>>;
getOne<TSelect extends SelectWithExpand<Collection>>(
getOne<TSelect extends SelectWithExpand<Collection> = {}>(
id: string,
options?: {
select?: TSelect;
Expand All @@ -83,13 +83,13 @@ export interface ViewCollectionService<

export interface BaseCollectionService<Collection extends GenericCollection>
extends ViewCollectionService<Collection> {
create<TSelect extends SelectWithExpand<Collection>>(
create<TSelect extends SelectWithExpand<Collection> = {}>(
bodyParams: Collection['create'],
options?: {
select?: TSelect;
} & SendOptions
): Promise<ResolveSelectWithExpand<Collection, TSelect>>;
update<TSelect extends SelectWithExpand<Collection>>(
update<TSelect extends SelectWithExpand<Collection> = {}>(
id: string,
bodyParams: Collection['update'],
options?: {
Expand All @@ -102,7 +102,7 @@ export interface BaseCollectionService<Collection extends GenericCollection>
export interface AuthCollectionService<Collection extends GenericCollection>
extends BaseCollectionService<Collection>,
Pick<RecordService, (typeof FORWARD_METHODS)[number]> {
authWithPassword<TSelect extends SelectWithExpand<Collection>>(
authWithPassword<TSelect extends SelectWithExpand<Collection> = {}>(
usernameOrEmail: string,
password: string,
options?: {
Expand All @@ -111,7 +111,7 @@ export interface AuthCollectionService<Collection extends GenericCollection>
): Promise<
RecordAuthResponse<ResolveSelectWithExpand<Collection, TSelect>>
>;
authWithOAuth2Code<TSelect extends SelectWithExpand<Collection>>(
authWithOAuth2Code<TSelect extends SelectWithExpand<Collection> = {}>(
provider: string,
code: string,
codeVerifier: string,
Expand All @@ -130,7 +130,7 @@ export interface AuthCollectionService<Collection extends GenericCollection>
createData?: Collection['create'];
} & SendOptions
): Promise<RecordAuthResponse<Collection['response']>>;
authRefresh<TSelect extends SelectWithExpand<Collection>>(
authRefresh<TSelect extends SelectWithExpand<Collection> = {}>(
options?: {
select?: TSelect;
} & SendOptions
Expand Down
5 changes: 2 additions & 3 deletions src/select.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,8 @@ export type SelectWithExpand<Collection extends GenericCollection> =
export type ResolveSelect<
TCollection extends GenericCollection,
TSelect extends Select<TCollection> | undefined
> = undefined extends TSelect
? TCollection['response']
: Extract<keyof TSelect, keyof TCollection['response']> extends never
> =
Extract<keyof TSelect, keyof TCollection['response']> extends never
? TCollection['response']
: {
[K in keyof TSelect &
Expand Down

0 comments on commit b4e749e

Please sign in to comment.