SIGN IN SIGN UP
honojs / hono UNCLAIMED

Web framework built on Web Standards

0 0 82 TypeScript

fix(request): return `string | undefined` from param() when path type is any (#4723)

* fix: return string | undefined from param() when path type is any

When middleware uses Context with a default path type parameter (any),
c.req.param('key') incorrectly returns string instead of string | undefined.
This is because ParamKeys<any> resolves to string, matching the first
overload that returns string.

Add a new overload that detects when P is any using the 0 extends (1 & P)
trick and returns string | undefined, ensuring type safety in middleware.

Fixes #3198

* ci: apply automated fixes

* test(request): add type tests for param() with any path type

* fixed the overload and test

---------

Co-authored-by: exe.dev user <exedev@queen-xray.exe.xyz>
Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
Co-authored-by: andrewdamelio <andrewdamelio@gmail.com>
Co-authored-by: Yusuke Wada <yusuke@kamawada.com>
A
Andrew D'Amelio committed
0f499152ee20daf4f394d1f0ef5cc700ce7e2735
Parent: 19d20d2
Committed by GitHub <noreply@github.com> on 3/4/2026, 7:26:53 AM