fix(zod-openapi): replace any type parameters in OpenAPIHonoOptions.defaultHook#1930
Open
Wajkie wants to merge 1 commit into
Open
fix(zod-openapi): replace any type parameters in OpenAPIHonoOptions.defaultHook#1930Wajkie wants to merge 1 commit into
Wajkie wants to merge 1 commit into
Conversation
|
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.
Fix: Replace
anytype parameters inOpenAPIHonoOptions.defaultHookProblem
OpenAPIHonoOptionstypesdefaultHookasHook<any, E, any, any>:This leaks
anyinto thecparameter of everydefaultHookcallback, even whenOpenAPIHonois fully parameterized with a concreteEnv. TheContext<E, P>insideHookresolves toContext<any, any>, which defeats strict type checking and causes failures with tools liketype-coverage --strict.Root cause
Hookis correctly typed:But the three
anydefaults passed at the call site undo that precision.Fix
T: unknown—defaultHookis a catch-all that applies to all routes regardless of their specific input shape.unknownis the correct type when the data type cannot be known at this level (as opposed toany, which silently opts out of type checking).P: string— a route path is always astring. Usinganyhere causesc.reqand related path-typed members to resolve toany.R: Response | void | Promise<Response | void>— these are the only meaningful return types for a hook.anyallows returning anything, including values that would be silently ignored.Impact
Before this change, users who set
defaultHookon a fully typedOpenAPIHono<BlankEnv>instance still getc: Context<any, any>in the callback. After this change,cis correctly inferred asContext<BlankEnv, string>without any annotation required.No behaviour changes — runtime is unaffected.