Skip to content

Commit 171d25c

Browse files
committed
update types
1 parent fcc4570 commit 171d25c

File tree

1 file changed

+42
-7
lines changed

1 file changed

+42
-7
lines changed

packages/kit/types/index.d.ts

Lines changed: 42 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1682,18 +1682,51 @@ declare module '@sveltejs/kit' {
16821682
}
16831683

16841684
type ValidatedConfig = RecursiveRequired<Config>;
1685-
export function error(status: number, body: App.Error): HttpError_1;
1686-
1687-
export function error(status: number, body?: {
1685+
/**
1686+
* Throws an error with a HTTP status code and an optional message.
1687+
* When called during request handling, this will cause SvelteKit to
1688+
* return an error response without invoking `handleError`.
1689+
* Make sure you're not catching the thrown error, which would prevent SvelteKit from handling it.
1690+
* @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.
1691+
* @param body An object that conforms to the App.Error type. If a string is passed, it will be used as the message property.
1692+
* @throws {HttpError} This error instructs SvelteKit to initiate HTTP error handling.
1693+
* @throws {Error} If the provided status is invalid (not between 400 and 599).
1694+
*/
1695+
export function error(status: NumericRange<400, 599>, body: App.Error): never;
1696+
/**
1697+
* Throws an error with a HTTP status code and an optional message.
1698+
* When called during request handling, this will cause SvelteKit to
1699+
* return an error response without invoking `handleError`.
1700+
* Make sure you're not catching the thrown error, which would prevent SvelteKit from handling it.
1701+
* @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.
1702+
* @param body An object that conforms to the App.Error type. If a string is passed, it will be used as the message property.
1703+
* @throws {HttpError} This error instructs SvelteKit to initiate HTTP error handling.
1704+
* @throws {Error} If the provided status is invalid (not between 400 and 599).
1705+
*/
1706+
export function error(status: NumericRange<400, 599>, body?: {
16881707
message: string;
1689-
} extends App.Error ? App.Error | string | undefined : never): HttpError_1;
1708+
} extends App.Error ? App.Error | string | undefined : never): never;
16901709
/**
1691-
* Create a `Redirect` object. If thrown during request handling, SvelteKit will return a redirect response.
1710+
* Checks whether this is an error thrown by {@link error}.
1711+
* @param status The status to filter for.
1712+
* */
1713+
export function isHttpError<T extends number>(e: unknown, status?: T | undefined): e is HttpError_1 & {
1714+
status: T extends undefined ? never : T;
1715+
};
1716+
/**
1717+
* Redirect a request. When called during request handling, SvelteKit will return a redirect response.
16921718
* Make sure you're not catching the thrown redirect, which would prevent SvelteKit from handling it.
16931719
* @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.
16941720
* @param location The location to redirect to.
1695-
*/
1696-
export function redirect(status: 300 | 301 | 302 | 303 | 304 | 305 | 306 | 307 | 308, location: string | URL): Redirect_1;
1721+
* @throws {Redirect} This error instructs SvelteKit to redirect to the specified location.
1722+
* @throws {Error} If the provided status is invalid.
1723+
* */
1724+
export function redirect(status: NumericRange<300, 308>, location: string | URL): never;
1725+
/**
1726+
* Checks whether this is a redirect thrown by {@link redirect}.
1727+
* @param e The object to check.
1728+
* */
1729+
export function isRedirect(e: unknown): e is Redirect_1;
16971730
/**
16981731
* Create a JSON `Response` object from the supplied data.
16991732
* @param data The value that will be serialized as JSON.
@@ -1726,6 +1759,8 @@ declare module '@sveltejs/kit' {
17261759
* ```
17271760
* */
17281761
export function resolvePath(id: string, params: Record<string, string | undefined>): string;
1762+
export type LessThan<TNumber extends number, TArray extends any[] = []> = TNumber extends TArray['length'] ? TArray[number] : LessThan<TNumber, [...TArray, TArray['length']]>;
1763+
export type NumericRange<TStart extends number, TEnd extends number> = Exclude<TEnd | LessThan<TEnd>, LessThan<TStart>>;
17291764
export const VERSION: string;
17301765
}
17311766

0 commit comments

Comments
 (0)