From 8828743a1f8442162f0146d81d5d4112d9c31239 Mon Sep 17 00:00:00 2001 From: Ignatius Bagus Date: Fri, 2 Jul 2021 14:10:12 +0700 Subject: [PATCH] [docs] sync updates from #1778 and #1791 (#1802) --- documentation/docs/01-routing.md | 15 ++++++++++----- documentation/docs/03-loading.md | 22 +++++++++++++++------- 2 files changed, 25 insertions(+), 12 deletions(-) diff --git a/documentation/docs/01-routing.md b/documentation/docs/01-routing.md index 93ebcf3fc656..8b60689931c0 100644 --- a/documentation/docs/01-routing.md +++ b/documentation/docs/01-routing.md @@ -49,6 +49,7 @@ Endpoints are modules written in `.js` (or `.ts`) files that export functions co ```ts type Headers = Record; +type DefaultBody = JSONValue | Uint8Array; type Request, Body = unknown> = { method: string; @@ -62,15 +63,19 @@ type Request, Body = unknown> = { locals: Locals; // populated by hooks handle }; -type EndpointOutput = { +type EndpointOutput = { status?: number; headers?: Headers; - body?: string | Uint8Array | JSONValue; + body?: Body; }; -type RequestHandler> = ( - request: Request -) => void | EndpointOutput | Promise; +type RequestHandler< + Locals = Record, + Input = unknown, + Output extends DefaultBody = DefaultBody +> = ( + request: Request +) => void | EndpointOutput | Promise>; ``` ```js diff --git a/documentation/docs/03-loading.md b/documentation/docs/03-loading.md index 1b7c57d0ec10..3aa7e6035855 100644 --- a/documentation/docs/03-loading.md +++ b/documentation/docs/03-loading.md @@ -7,26 +7,34 @@ A component that defines a page or a layout can export a `load` function that ru Our example blog page might contain a `load` function like the following. Note the `context="module"` — this is necessary because `load` runs before the component is rendered: ```ts -type LoadInput = { +type LoadInput< + PageParams extends Record = Record, + Context extends Record = Record, + Session = any +> = { page: { host: string; path: string; - params: Record; + params: PageParams; query: URLSearchParams; }; fetch: (info: RequestInfo, init?: RequestInit) => Promise; - session: any; - context: Record; + session: Session; + context: Context; }; -type LoadOutput = { +type LoadOutput< + Props extends Record = Record, + Context extends Record = Record +> = { status?: number; error?: string | Error; redirect?: string; - props?: Record; - context?: Record; + props?: Props; + context?: Context; maxage?: number; }; + ``` ```html