0
Fork 0
mirror of https://github.com/withastro/astro.git synced 2024-12-16 21:46:22 -05:00

Make APIRoute generic like APIContext (#7521)

This commit is contained in:
Ken Powers 2023-07-03 03:58:27 -04:00 committed by GitHub
parent bc9ce779d3
commit 19c2d43ea4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 4 deletions

View file

@ -0,0 +1,5 @@
---
"astro": patch
---
Add `Props` generic for `APIRoute` type

View file

@ -1764,21 +1764,21 @@ export interface APIContext<Props extends Record<string, any> = Record<string, a
locals: App.Locals; locals: App.Locals;
} }
export type Props = Record<string, unknown>;
export interface EndpointOutput { export interface EndpointOutput {
body: Body; body: Body;
encoding?: BufferEncoding; encoding?: BufferEncoding;
} }
export type APIRoute = ( export type APIRoute<Props extends Record<string, any> = Record<string, any>> = (
context: APIContext context: APIContext<Props>
) => EndpointOutput | Response | Promise<EndpointOutput | Response>; ) => EndpointOutput | Response | Promise<EndpointOutput | Response>;
export interface EndpointHandler { export interface EndpointHandler {
[method: string]: APIRoute | ((params: Params, request: Request) => EndpointOutput | Response); [method: string]: APIRoute | ((params: Params, request: Request) => EndpointOutput | Response);
} }
export type Props = Record<string, unknown>;
export interface AstroRenderer { export interface AstroRenderer {
/** Name of the renderer. */ /** Name of the renderer. */
name: string; name: string;