-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
narrow down possible status codes for redirects to 300-308 #7615
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
🦋 Changeset detectedLatest commit: eed49f0 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
Can't we make the type more generic ? type RangeStartArray<
LENGTH extends number,
ACC extends unknown[] = [],
> = ACC['length'] extends LENGTH
? ACC
: RangeStartArray<LENGTH, [...ACC, 1]>
type NumericRangeBuilder<
START_ARR extends number[],
END extends number,
ACC extends number = never>
= START_ARR['length'] extends END
? ACC | END
: NumericRangeBuilder<[...START_ARR, 1], END, ACC | START_ARR['length']>
/**
* A type that represents a range of numbers 'FROM' to `END` (inclusive)
*
* @example
* type Range = NumericRange<100, 200> // 100 | 101 ... 199 | 200
*/
export type NumericRange<FROM extends number, TO extends number> = NumericRangeBuilder<RangeStartArray<FROM>, TO>
/**
*
* @property {number} informational - 1xx
* @property {number} success - 2xx
* @property {number} redirection - 3xx
* @property {number} clientError - 4xx
* @property {number} serverError - 5xx
*
* @see https://developer.mozilla.org/en-US/docs/Web/HTTP/Status
*/
export type HttpStatusCode = {
informational: NumericRange<1, 199>;
success: NumericRange<200, 299>;
redirect: NumericRange<300, 399>;
clientError: NumericRange<400, 499>;
serverError: NumericRange<500, 599>;
} /**
* Creates a `Redirect` object. If thrown during request handling, SvelteKit will
* return a redirect response.
* @param status The HTTP redirect status code (300-399)
* @param location The location to redirect to
*/
export function redirect(status: HttpStatusCode['redirect'], location: string): Redirect; |
If it would be more performant.. then probably yes. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Number range generator is something for another PR, if ever - I'd rather have more simple types. In this case it's ok because it's only a handful of numbers, which can be hardcoded.
thank you! |
closes #7614
Please don't delete this checklist! Before submitting the PR, please make sure you do the following:
Tests
pnpm test
and lint the project withpnpm lint
andpnpm check
Changesets
pnpm changeset
and following the prompts. All changesets should bepatch
until SvelteKit 1.0