[config] Fix rewrite() and redirect() return types for VercelConfig compatibility#15566
Merged
MatthewStanciu merged 5 commits intovercel:mainfrom Mar 16, 2026
Merged
Conversation
The simple 2-arg `rewrite(source, destination)` and `redirect(source, destination)` calls always produce `Rewrite` / `Redirect` objects at runtime, but were typed as returning `Rewrite | Route` / `Redirect | Route`. Since `Route.source` is `string | undefined` (made optional in vercel#15016) while `Rewrite.source` is `string`, the union is not assignable to `Rewrite[]` / `Redirect[]` in `VercelConfig`. Narrow the 2-arg overloads to return `Rewrite` / `Redirect` so the documented pattern works without type errors: ```ts export const config: VercelConfig = { rewrites: [ routes.rewrite('/about', '/about-our-company.html'), // no longer errors ], }; ``` The callback and options overloads retain `Rewrite | Route` / `Redirect | Route` since those can legitimately produce `Route` objects with transforms.
🦋 Changeset detectedLatest commit: 99bfa7e 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 |
Contributor
|
Low Risk — Type narrowing + bug fix in config package; no auth/billing/schema changes.
Assessed at 99bfa7e. |
Fixes the return types of rewrite() and redirect() to ensure compatibility with VercelConfig.
… destination has env vars The no-transforms code path was eagerly converting to Route format (regex src/dest) when the destination contained env vars. Since both Rewrite and Redirect already have an env field, return the high-level type and let convertRewrites/convertRedirects handle regex conversion downstream.
MatthewStanciu
approved these changes
Mar 16, 2026
Contributor
MatthewStanciu
left a comment
There was a problem hiding this comment.
Oof, thanks for catching this & submitting a fix! We need a better way to keep these in sync with routing-utils
This reverts commit 80509c4.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
rewrite(source, destination)overload fromRewrite | RoutetoRewriteredirect(source, destination)overload fromRedirect | RoutetoRedirectRoute(withsrc/dest) instead ofRewrite/Redirect(withsource/destination) when the destination contained env vars fromdeploymentEnv()Bug
Since #15016 made
Route.sourceoptional (string | undefined), the unionRewrite | Routeis no longer assignable toRewrite[]inVercelConfig.rewrites, causing a type error on the documented usage pattern:Type fix
The 2-arg overloads always produce
Rewrite/Redirectat runtime, so the return type is narrowed to match. The callback and options overloads retainRewrite | Route/Redirect | Route.Runtime fix
When the destination contained env var references (e.g.
deploymentEnv('API_HOST')), the no-transforms code path eagerly converted toRouteformat (regexsrc/dest). This meant the returned object hadsrc/destproperties instead of the declaredsource/destination, which would break if passed toconvertRewrites()downstream. Since bothRewriteandRedirectalready have anenvfield, we now return the high-level type directly and letconvertRewrites/convertRedirectshandle regex conversion.