@@ -1682,18 +1682,51 @@ declare module '@sveltejs/kit' {
1682
1682
}
1683
1683
1684
1684
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 ?: {
1688
1707
message : string ;
1689
- } extends App . Error ? App . Error | string | undefined : never ) : HttpError_1 ;
1708
+ } extends App . Error ? App . Error | string | undefined : never ) : never ;
1690
1709
/**
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.
1692
1718
* Make sure you're not catching the thrown redirect, which would prevent SvelteKit from handling it.
1693
1719
* @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.
1694
1720
* @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 ;
1697
1730
/**
1698
1731
* Create a JSON `Response` object from the supplied data.
1699
1732
* @param data The value that will be serialized as JSON.
@@ -1726,6 +1759,8 @@ declare module '@sveltejs/kit' {
1726
1759
* ```
1727
1760
* */
1728
1761
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 > > ;
1729
1764
export const VERSION : string ;
1730
1765
}
1731
1766
0 commit comments