Skip to content

types: fix misleading Headers type definition #1611

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/few-cooks-peel.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@sveltejs/kit': patch
---

Fix misleading Headers type definition for possible undefined values
2 changes: 1 addition & 1 deletion documentation/docs/01-routing.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ A file or directory can have multiple dynamic parts, like `[id]-[category].svelt
Endpoints are modules written in `.js` (or `.ts`) files that export functions corresponding to HTTP methods. For example, our hypothetical blog page, `/blog/cool-article`, might request data from `/blog/cool-article.json`, which could be represented by a `src/routes/blog/[slug].json.js` endpoint:

```ts
type Headers = Record<string, string>;
type Headers = Record<string, string | undefined>;
type DefaultBody = JSONValue | Uint8Array;

type Request<Locals = Record<string, any>, Body = unknown> = {
Expand Down
2 changes: 1 addition & 1 deletion documentation/docs/04-hooks.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ If unimplemented, defaults to `({ request, resolve }) => resolve(request)`.
To add custom data to the request, which is passed to endpoints, populate the `request.locals` object, as shown below.

```ts
type Headers = Record<string, string>;
type Headers = Record<string, string | undefined>;

type Request<Locals = Record<string, any>> = {
method: string;
Expand Down
2 changes: 1 addition & 1 deletion packages/kit/types/endpoint.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ type DefaultBody = JSONValue | Uint8Array;

export type EndpointOutput<Body extends DefaultBody = DefaultBody> = {
status?: number;
headers?: Partial<Headers>;
headers?: Headers;
body?: Body;
};

Expand Down
2 changes: 1 addition & 1 deletion packages/kit/types/helper.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export type ParameterizedBody<Body = unknown> = Body extends FormData
// always follow this type, and response headers, in which
// 'set-cookie' is a `string[]` (or at least `string | string[]`)
// but this can't happen until TypeScript 4.3
export type Headers = Record<string, string>;
export type Headers = Record<string, string | undefined>;

export type Location<Params extends Record<string, string> = Record<string, string>> = {
host: string;
Expand Down