Skip to content
Merged
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/lucky-gifts-jump.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@sveltejs/kit': patch
---

[fix] export HttpError/Redirect interface
37 changes: 29 additions & 8 deletions packages/kit/types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import {
UniqueInterface
} from './private.js';
import { SSRNodeLoader, SSRRoute, ValidatedConfig } from './internal.js';
import { HttpError, Redirect } from '../src/runtime/control.js';

export { PrerenderOption } from './private.js';

Expand Down Expand Up @@ -53,13 +52,6 @@ type OptionalUnion<
A extends keyof U = U extends U ? keyof U : never
> = U extends unknown ? { [P in Exclude<A, keyof U>]?: never } & U : never;

// Needs to be here, else ActionData will be resolved to unknown - probably because of "d.ts file imports .js file" in combination with allowJs
export interface ValidationError<T extends Record<string, unknown> | undefined = undefined>
extends UniqueInterface {
status: number;
data: T;
}

type UnpackValidationError<T> = T extends ValidationError<infer X>
? X
: T extends void
Expand Down Expand Up @@ -752,6 +744,16 @@ export function error(
body?: { message: string } extends App.Error ? App.Error | string | undefined : never
): HttpError;

/**
* The object returned by the `error` function
*/
export interface HttpError extends UniqueInterface {
/** The HTTP status code */
status: number;
/** The error message */
body: { message: string } extends App.Error ? App.Error | string | undefined : App.Error;
}

/**
* Creates a `Redirect` object. If thrown during request handling, SvelteKit will
* return a redirect response.
Expand All @@ -761,6 +763,16 @@ export function redirect(
location: string
): Redirect;

/**
* The object returned by the `redirect` function
*/
export interface Redirect extends UniqueInterface {
/** The HTTP status code */
status: 300 | 301 | 302 | 303 | 304 | 305 | 306 | 307 | 308;
/** The location to redirect to */
location: string;
}

/**
* Generates a JSON `Response` object from the supplied data.
*/
Expand All @@ -773,3 +785,12 @@ export function invalid<T extends Record<string, unknown> | undefined>(
status: number,
data?: T
): ValidationError<T>;

/**
* The object returned by the `invalid` function
*/
export interface ValidationError<T extends Record<string, unknown> | undefined = undefined>
extends UniqueInterface {
status: number;
data: T;
}