Skip to content

Commit a37eb3a

Browse files
committed
refactor(api): Include R into ResponseOfEndpoint
1 parent 88bad85 commit a37eb3a

File tree

3 files changed

+26
-27
lines changed

3 files changed

+26
-27
lines changed

api/pages/project.ts

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -76,24 +76,22 @@ export const get = <R extends Response | undefined = Response>(
7676
project: string,
7777
options?: ListPagesOption<R>,
7878
): Promise<
79-
| ResponseOfEndpoint<{
79+
ResponseOfEndpoint<{
8080
200: PageList;
8181
404: NotFoundError;
8282
401: NotLoggedInError;
8383
403: NotMemberError;
84-
}>
85-
| (undefined extends R ? undefined : never)
84+
}, R>
8685
> =>
8786
setDefaults(options ?? {}).fetch(
8887
makeGetRequest(project, options),
8988
) as Promise<
90-
| ResponseOfEndpoint<{
89+
ResponseOfEndpoint<{
9190
200: PageList;
9291
404: NotFoundError;
9392
401: NotLoggedInError;
9493
403: NotMemberError;
95-
}>
96-
| (undefined extends R ? undefined : never)
94+
}, R>
9795
>;
9896

9997
/**

api/pages/project/title.ts

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -63,22 +63,20 @@ export const get = <R extends Response | undefined = Response>(
6363
title: string,
6464
options?: GetPageOption<R>,
6565
): Promise<
66-
| ResponseOfEndpoint<{
66+
ResponseOfEndpoint<{
6767
200: Page;
6868
404: NotFoundError;
6969
401: NotLoggedInError;
7070
403: NotMemberError;
71-
}>
72-
| (undefined extends R ? undefined : never)
71+
}, R>
7372
> =>
7473
setDefaults(options ?? {}).fetch(
7574
makeGetRequest(project, title, options),
7675
) as Promise<
77-
| ResponseOfEndpoint<{
76+
ResponseOfEndpoint<{
7877
200: Page;
7978
404: NotFoundError;
8079
401: NotLoggedInError;
8180
403: NotMemberError;
82-
}>
83-
| (undefined extends R ? undefined : never)
81+
}, R>
8482
>;

targeted_response.ts

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -86,21 +86,24 @@ export type { StatusCode, SuccessfulStatus };
8686
*/
8787
export type ResponseOfEndpoint<
8888
ResponseBodyMap extends Record<number, unknown> = Record<StatusCode, string>,
89-
> = {
90-
[Status in StatusCode | keyof ResponseBodyMap]: Status extends number
91-
? ResponseBodyMap[Status] extends
92-
| string
93-
| Exclude<
94-
JsonCompatible<ResponseBodyMap[Status]>,
95-
string | number | boolean | null
96-
>
97-
| Uint8Array
98-
| FormData
99-
| Blob ? TargetedResponse<Status, ResponseBodyMap[Status]>
100-
: Status extends StatusCode ? TargetedResponse<Status, string>
101-
: never
102-
: never;
103-
}[StatusCode | keyof ResponseBodyMap];
89+
R extends Response | undefined = Response,
90+
> =
91+
| {
92+
[Status in StatusCode | keyof ResponseBodyMap]: Status extends number
93+
? ResponseBodyMap[Status] extends
94+
| string
95+
| Exclude<
96+
JsonCompatible<ResponseBodyMap[Status]>,
97+
string | number | boolean | null
98+
>
99+
| Uint8Array
100+
| FormData
101+
| Blob ? TargetedResponse<Status, ResponseBodyMap[Status]>
102+
: Status extends StatusCode ? TargetedResponse<Status, string>
103+
: never
104+
: never;
105+
}[StatusCode | keyof ResponseBodyMap]
106+
| (undefined extends R ? undefined : never);
104107

105108
/**
106109
* Type-safe {@linkcode Response} object

0 commit comments

Comments
 (0)