Skip to content

Commit

Permalink
created DefaultBody type, which can be used as the default for Reques…
Browse files Browse the repository at this point in the history
…t or Response bodies. Added a generic parameter to `RequestHandler` and an generic parameter to `EndpointOutput`. Together, these let you specify the type of the body of the Response you want to return from a RequestHandler function. The default of both of these parameters is `DefaultBody`.
  • Loading branch information
dannyvelas committed Jun 29, 2021
1 parent b556c55 commit b1d5f97
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions packages/kit/types/endpoint.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,16 @@ type JSONValue =
| JSONValue[]
| { [key: string]: JSONValue };

export type EndpointOutput = {
type DefaultBody = JSONValue | Uint8Array;

export type EndpointOutput<ResBody = DefaultBody> = {
status?: number;
headers?: Partial<Headers>;
body?: JSONValue | Uint8Array;
body?: ResBody;
};

export type RequestHandler<Locals = Record<string, any>, Body = unknown> = (
request: ServerRequest<Locals, Body>
) => MaybePromise<void | EndpointOutput>;
export type RequestHandler<
Locals = Record<string, any>,
ReqBody = unknown,
ResBody = DefaultBody
> = (request: ServerRequest<Locals, ReqBody>) => MaybePromise<void | EndpointOutput<ResBody>>;

0 comments on commit b1d5f97

Please sign in to comment.