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/wicked-olives-fold.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@sveltejs/kit': patch
---

fix: adjust error overload for optional `App.Error` parameters
4 changes: 2 additions & 2 deletions packages/kit/src/exports/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,11 @@ export { VERSION } from '../version.js';
* Make sure you're not catching the thrown error, which would prevent SvelteKit from handling it.
* @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 {string} message The error message.
* @param {{ status: number; message: string } extends App.Error ? never : Omit<App.Error, 'status' | 'message'>} properties Additional properties of the App.Error type.
* @param {keyof Omit<App.Error, 'status' | 'message'> extends never ? never : Omit<App.Error, 'status' | 'message'>} properties Additional properties of the App.Error type.
* @overload
* @param {number} status
* @param {string} message
* @param {{ status: number; message: string } extends App.Error ? never : Omit<App.Error, 'status' | 'message'>} properties
* @param {keyof Omit<App.Error, 'status' | 'message'> extends never ? never : Omit<App.Error, 'status' | 'message'>} properties
* @return {never}
* @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).
Expand Down
13 changes: 13 additions & 0 deletions packages/kit/test/types/error.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
import { error, type HandleClientError, type HandleServerError } from '@sveltejs/kit';
import type { StandardSchemaV1 } from '@standard-schema/spec';

declare global {
namespace App {
interface Error {
description?: string;
}
}
}

const app_error: App.Error = { status: 500, message: 'Unexpected error' };

// @ts-expect-error App.Error requires status
Expand Down Expand Up @@ -98,9 +106,14 @@ function f() {
error(400);
}

function g() {
error(400, 'Bad request', { description: 'Invalid request data' });
}

a;
b;
c;
d;
e;
f;
g;
5 changes: 1 addition & 4 deletions packages/kit/types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2443,10 +2443,7 @@ declare module '@sveltejs/kit' {
* @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, message: string, properties: {
status: number;
message: string;
} extends App.Error ? never : Omit<App.Error, "status" | "message">): never;
export function error(status: number, message: string, properties: keyof Omit<App.Error, "status" | "message"> extends never ? never : Omit<App.Error, "status" | "message">): never;
/**
* Throws an error with a HTTP status code and an optional message.
* When called during request handling, this will cause SvelteKit to
Expand Down
Loading