hapijs / hapi

The Simple, Secure Framework Developers Trust

Home Page:https://hapi.dev

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

HTTP_METHODS_PARTIAL_LOWERCASE is missing `head`

edoardo-bluframe opened this issue · comments

Runtime

node.js

Runtime version

18

Module version

21

Last module version without issue

No response

Used with

No response

Any other relevant information

No response

What are you trying to achieve or the steps to reproduce?

We have a controller that must only respond to the head method

Hapi works with it by creating a get route and then checking request.method for method === "head"

But types from @hapi/hapi do not support head!

In lib/types/utils.d.ts line 14:

export type HTTP_METHODS_PARTIAL_LOWERCASE = 'get' | 'post' | 'put' | 'patch' | 'delete' | 'options';

All we need to do to fix this is add | 'head' to the list!

What was the result you got?

if(method === "head") {

typescript: This comparison appears to be unintentional because the types 'HTTP_METHODS_PARTIAL_LOWERCASE' and '"head"' have no overlap. [2367]

What result did you expect?

Expected it to work!

I can raise a PR if you want?

Thanks for the report.

I understand the issue, but your proposed fix is not suitable, as we don't want to allow head to be allowed in the route method field. I have looked further into it, and revised the method typings to be correct for all method fields in #4493. The exact typings for each method turns out to be unique for all of them.