Skip to content

Handle Express 5 typed route params as string or string[] - #12033

Draft
znarf wants to merge 1 commit into
renovate/express-serve-static-core-5.xfrom
claude/type-ci-task-ml18qc
Draft

Handle Express 5 typed route params as string or string[]#12033
znarf wants to merge 1 commit into
renovate/express-serve-static-core-5.xfrom
claude/type-ci-task-ml18qc

Conversation

@znarf

@znarf znarf commented Aug 21, 2026

Copy link
Copy Markdown
Member

Summary

This PR addresses compatibility with Express 5's updated type definitions for route parameters. Express 5 types req.params values as string | 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

  • Added getRouteParam() utility function in server/lib/request-utils.ts that safely extracts route parameters and handles the string | string[] union type by joining array values back into a path string
  • Updated Express type definition in server/types/express.d.ts to reflect Express 5's params: Record<string, string | string[]> typing
  • Replaced direct req.params access with getRouteParam() 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

@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
@coderabbitai

coderabbitai Bot commented Aug 21, 2026

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: c421405f-4dec-4d8d-bdce-e0819df727cf

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@znarf
znarf marked this pull request as draft August 21, 2026 08:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants