You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
What are you trying to achieve or the steps to reproduce?
Take advantage of Joi's type handling to directly reference appropriately typed parameters in request.params and request.query. For example:
functiongreetUser(id: number){assert(typeofid==="number","ID must be a number");return`Hello, user with ID ${id}!`;}server.route({method: "GET",path: "/hello/{id}",handler: (request,_h)=>{// request.params.id is number, not string, because of Joi validationreturn{message: greetUser(request.params.id)};},options: {validate: {params: Joi.object({id: Joi.number().required(),}),},},});
What was the result you got?
Starting in Hapi 21.4.5:
Argument of type 'string' is not assignable to parameter of type 'number'.ts(2345)
What result did you expect?
No errors.
I believe that the stricter types in #4562 are too strict. I appreciate stricter typing (even if it breaks compilation in patch releases - #4563) but this seems too strict - from what I understand, relying on Joi to validate queries and route parameters and coerce / convert their types is a core feature of Hapi and is (I assume) a common practice, but the new types act like it isn't permitted / doesn't happen.
By default, without Joi doing type coercion for you via validations, params WILL be a string. Typescript has no knowledge of what you're doing to convert params into a specific type. Create your own refs and you solve the problem. any is ambiguous. The goal in the last PR was to make types LESS ambiguous.
By default, without Joi doing type coercion for you via validations, params WILL be a string. Typescript has no knowledge of what you're doing to convert params into a specific type. Create your own refs and you solve the problem. any is ambiguous. The goal in the last PR was to make types LESS ambiguous.
Arguably unknown might have been a better default.
Activity
joshkel commentedon Feb 20, 2026
As a workaround within my own codebase, I'm adding the pre-21.4.5
ParamsandQuerydefinitions using module augmentation.damusix commentedon Feb 22, 2026
@joshkel you can set these yourself, and you should.
https://github.com/hapijs/hapi/blob/master/typescript.md#example
By default, without Joi doing type coercion for you via validations, params WILL be a string. Typescript has no knowledge of what you're doing to convert params into a specific type. Create your own refs and you solve the problem.
anyis ambiguous. The goal in the last PR was to make types LESS ambiguous.kanongil commentedon Feb 22, 2026
Arguably
unknownmight have been a better default.damusix commentedon Feb 22, 2026
@kanongil even though true the default is
string?