From 9c646f2ff580518c93416fccbcd7bbd3bc578eaa Mon Sep 17 00:00:00 2001 From: Chew Tee Ming Date: Thu, 21 Nov 2024 11:14:55 +0800 Subject: [PATCH 1/3] change public helper types from class to interface type --- packages/kit/src/exports/index.js | 12 ++++++------ packages/kit/types/index.d.ts | 25 +++++-------------------- 2 files changed, 11 insertions(+), 26 deletions(-) diff --git a/packages/kit/src/exports/index.js b/packages/kit/src/exports/index.js index 5454a2e15e31..dd84699c92b0 100644 --- a/packages/kit/src/exports/index.js +++ b/packages/kit/src/exports/index.js @@ -33,7 +33,7 @@ export { VERSION } from '../version.js'; * @param {number} status * @param {App.Error} body * @return {never} - * @throws {HttpError} This error instructs SvelteKit to initiate HTTP error handling. + * @throws {import('./public.js').HttpError} This error instructs SvelteKit to initiate HTTP error handling. * @throws {Error} If the provided status is invalid (not between 400 and 599). */ /** @@ -47,7 +47,7 @@ export { VERSION } from '../version.js'; * @param {number} status * @param {{ message: string } extends App.Error ? App.Error | string | undefined : never} [body] * @return {never} - * @throws {HttpError} This error instructs SvelteKit to initiate HTTP error handling. + * @throws {import('./public.js').HttpError} This error instructs SvelteKit to initiate HTTP error handling. * @throws {Error} If the provided status is invalid (not between 400 and 599). */ /** @@ -58,7 +58,7 @@ export { VERSION } from '../version.js'; * @param {number} status The [HTTP status code](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status#client_error_responses). Must be in the range 400-599. * @param {{ message: string } extends App.Error ? App.Error | string | undefined : never} body An object that conforms to the App.Error type. If a string is passed, it will be used as the message property. * @return {never} - * @throws {HttpError} This error instructs SvelteKit to initiate HTTP error handling. + * @throws {import('./public.js').HttpError} This error instructs SvelteKit to initiate HTTP error handling. * @throws {Error} If the provided status is invalid (not between 400 and 599). */ export function error(status, body) { @@ -74,7 +74,7 @@ export function error(status, body) { * @template {number} T * @param {unknown} e * @param {T} [status] The status to filter for. - * @return {e is (HttpError & { status: T extends undefined ? never : T })} + * @return {e is (import('./public.js').HttpError & { status: T extends undefined ? never : T })} */ export function isHttpError(e, status) { if (!(e instanceof HttpError)) return false; @@ -86,7 +86,7 @@ export function isHttpError(e, status) { * Make sure you're not catching the thrown redirect, which would prevent SvelteKit from handling it. * @param {300 | 301 | 302 | 303 | 304 | 305 | 306 | 307 | 308 | ({} & number)} status The [HTTP status code](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status#redirection_messages). Must be in the range 300-308. * @param {string | URL} location The location to redirect to. - * @throws {Redirect} This error instructs SvelteKit to redirect to the specified location. + * @throws {import('./public.js').Redirect} This error instructs SvelteKit to redirect to the specified location. * @throws {Error} If the provided status is invalid. * @return {never} */ @@ -105,7 +105,7 @@ export function redirect(status, location) { /** * Checks whether this is a redirect thrown by {@link redirect}. * @param {unknown} e The object to check. - * @return {e is Redirect} + * @return {e is import('./public.js').Redirect} */ export function isRedirect(e) { return e instanceof Redirect; diff --git a/packages/kit/types/index.d.ts b/packages/kit/types/index.d.ts index 237b3e3ff57e..c88b7fe13d97 100644 --- a/packages/kit/types/index.d.ts +++ b/packages/kit/types/index.d.ts @@ -1765,7 +1765,7 @@ declare module '@sveltejs/kit' { * Make sure you're not catching the thrown error, which would prevent SvelteKit from handling it. * @param status The [HTTP status code](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status#client_error_responses). Must be in the range 400-599. * @param body An object that conforms to the App.Error type. If a string is passed, it will be used as the message property. - * @throws {HttpError} This error instructs SvelteKit to initiate HTTP error handling. + * @throws {import('./public.js').HttpError} This error instructs SvelteKit to initiate HTTP error handling. * @throws {Error} If the provided status is invalid (not between 400 and 599). */ export function error(status: number, body: App.Error): never; @@ -1776,7 +1776,7 @@ declare module '@sveltejs/kit' { * Make sure you're not catching the thrown error, which would prevent SvelteKit from handling it. * @param status The [HTTP status code](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status#client_error_responses). Must be in the range 400-599. * @param body An object that conforms to the App.Error type. If a string is passed, it will be used as the message property. - * @throws {HttpError} This error instructs SvelteKit to initiate HTTP error handling. + * @throws {import('./public.js').HttpError} This error instructs SvelteKit to initiate HTTP error handling. * @throws {Error} If the provided status is invalid (not between 400 and 599). */ export function error(status: number, body?: { @@ -1786,7 +1786,7 @@ declare module '@sveltejs/kit' { * Checks whether this is an error thrown by {@link error}. * @param status The status to filter for. * */ - export function isHttpError(e: unknown, status?: T | undefined): e is HttpError_1 & { + export function isHttpError(e: unknown, status?: T | undefined): e is HttpError & { status: T extends undefined ? never : T; }; /** @@ -1794,7 +1794,7 @@ declare module '@sveltejs/kit' { * Make sure you're not catching the thrown redirect, which would prevent SvelteKit from handling it. * @param status The [HTTP status code](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status#redirection_messages). Must be in the range 300-308. * @param location The location to redirect to. - * @throws {Redirect} This error instructs SvelteKit to redirect to the specified location. + * @throws {import('./public.js').Redirect} This error instructs SvelteKit to redirect to the specified location. * @throws {Error} If the provided status is invalid. * */ export function redirect(status: 300 | 301 | 302 | 303 | 304 | 305 | 306 | 307 | 308 | ({} & number), location: string | URL): never; @@ -1802,7 +1802,7 @@ declare module '@sveltejs/kit' { * Checks whether this is a redirect thrown by {@link redirect}. * @param e The object to check. * */ - export function isRedirect(e: unknown): e is Redirect_1; + export function isRedirect(e: unknown): e is Redirect; /** * Create a JSON `Response` object from the supplied data. * @param data The value that will be serialized as JSON. @@ -1834,21 +1834,6 @@ declare module '@sveltejs/kit' { export type LessThan = TNumber extends TArray['length'] ? TArray[number] : LessThan; export type NumericRange = Exclude, LessThan>; export const VERSION: string; - class HttpError_1 { - - constructor(status: number, body: { - message: string; - } extends App.Error ? (App.Error | string | undefined) : App.Error); - status: number; - body: App.Error; - toString(): string; - } - class Redirect_1 { - - constructor(status: 300 | 301 | 302 | 303 | 304 | 305 | 306 | 307 | 308, location: string); - status: 301 | 302 | 303 | 307 | 308 | 300 | 304 | 305 | 306; - location: string; - } export {}; } From f2d7a7c5d1f5f8bc56a1fca5d13f5df581ca955c Mon Sep 17 00:00:00 2001 From: Chew Tee Ming Date: Thu, 21 Nov 2024 11:18:17 +0800 Subject: [PATCH 2/3] changeset --- .changeset/light-singers-lie.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/light-singers-lie.md diff --git a/.changeset/light-singers-lie.md b/.changeset/light-singers-lie.md new file mode 100644 index 000000000000..9e3a2b282a9c --- /dev/null +++ b/.changeset/light-singers-lie.md @@ -0,0 +1,5 @@ +--- +'@sveltejs/kit': major +--- + +fix: change `error`, `isHttpError`, `redirect`, and `isRedirect` to refer to public type instead of internal class From 9c4eb9699529bc5e22c3654b5863d434d7a5f7c7 Mon Sep 17 00:00:00 2001 From: Tee Ming Date: Thu, 21 Nov 2024 11:23:00 +0800 Subject: [PATCH 3/3] Update .changeset/light-singers-lie.md --- .changeset/light-singers-lie.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.changeset/light-singers-lie.md b/.changeset/light-singers-lie.md index 9e3a2b282a9c..745edec0deb3 100644 --- a/.changeset/light-singers-lie.md +++ b/.changeset/light-singers-lie.md @@ -2,4 +2,4 @@ '@sveltejs/kit': major --- -fix: change `error`, `isHttpError`, `redirect`, and `isRedirect` to refer to public type instead of internal class +chore: change `error`, `isHttpError`, `redirect`, and `isRedirect` to refer to public type instead of internal class