From afb15c14a371cf8b4b217749b1cf03b7a2fe7df5 Mon Sep 17 00:00:00 2001 From: Nicolas Morel Date: Tue, 9 Apr 2024 11:40:34 +0200 Subject: [PATCH] types: allow server.match to receive lowercased methods --- lib/types/server/server.d.ts | 2 +- test/types/index.ts | 6 +++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/lib/types/server/server.d.ts b/lib/types/server/server.d.ts index e53a7a1eb..0970b7c17 100644 --- a/lib/types/server/server.d.ts +++ b/lib/types/server/server.d.ts @@ -475,7 +475,7 @@ export class Server { * @return Return value: the route information if found, otherwise null. * [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-servermatchmethod-path-host) */ - match(method: HTTP_METHODS, path: string, host?: string | undefined): RequestRoute | null; + match(method: HTTP_METHODS | Lowercase, path: string, host?: string | undefined): RequestRoute | null; /** * Registers a server method where: diff --git a/test/types/index.ts b/test/types/index.ts index 3b18fe611..e6a824b6b 100644 --- a/test/types/index.ts +++ b/test/types/index.ts @@ -4,6 +4,7 @@ import { expect } from '@hapi/code'; import { Plugin, Request, + RequestRoute, ResponseToolkit, Server, ServerRoute, @@ -77,7 +78,7 @@ const plugin: Plugin = { register: function (srv: MyServer, options) { check.type(options); - + srv.expose({ add: function (a: number, b: number) { @@ -89,6 +90,9 @@ const plugin: Plugin = { const loadedServer = await server.register({ plugin, options: { x: 10 } }); +check.type(server.match('GET', '/')); +check.type(server.match('get', '/')); + const sum = loadedServer.plugins.test.add(1, 2); expect(sum).to.equal(130); check.type(sum);