Handle Express 5 typed route params as string or string[] - #12033
Draft
znarf wants to merge 1 commit into
Draft
Conversation
@types/express-serve-static-core 5.1.x types `req.params` values as `string | string[]` (Express 5 wildcard params such as `/files/*path` capture a list of segments). Our `Express.Request` augmentation narrowed them to `Record<string, string>`, which made every `express.Request` fail to be assignable to the augmented global request type (~150 type errors across resolvers and controllers). Align the augmentation with `ParamsDictionary` and add a `getRouteParam` helper to read a route param as a string, used at the few call sites that consume params directly. All our routes use named params, so values are always plain strings at runtime; array values are joined back into a path for safety. Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01B5F9TzYZn4kkvZpPgiQtWG
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Plus Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
znarf
marked this pull request as draft
August 21, 2026 08:23
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
This PR addresses compatibility with Express 5's updated type definitions for route parameters. Express 5 types
req.paramsvalues asstring | string[]to account for wildcard route parameters that can capture multiple path segments. Since our codebase uses only named parameters (which are always strings), this change introduces a utility function to safely extract and normalize route parameters.Key Changes
getRouteParam()utility function inserver/lib/request-utils.tsthat safely extracts route parameters and handles thestring | string[]union type by joining array values back into a path stringserver/types/express.d.tsto reflect Express 5'sparams: Record<string, string | string[]>typingreq.paramsaccess withgetRouteParam()calls across multiple files:server/paymentProviders/paypal/webhook.ts(3 occurrences)server/middleware/authentication.ts(3 occurrences)server/lib/permalink/handler.ts(1 occurrence)server/controllers/files.ts(1 occurrence)server/controllers/legal-documents.ts(1 occurrence)Implementation Details
The
getRouteParam()function provides a centralized, type-safe way to access route parameters that works with both Express 4 and Express 5. It checks if the parameter value is an array and joins it with/to reconstruct the original path, otherwise returns the string value as-is. This ensures all route parameter access is consistent and handles the type union properly throughout the codebase.https://claude.ai/code/session_01B5F9TzYZn4kkvZpPgiQtWG