Skip to content

Commit

Permalink
types: allow server.match to receive lowercased methods
Browse files Browse the repository at this point in the history
  • Loading branch information
Marsup committed Apr 9, 2024
1 parent 200a5af commit afb15c1
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lib/types/server/server.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -475,7 +475,7 @@ export class Server<A = ServerApplicationState> {
* @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<HTTP_METHODS>, path: string, host?: string | undefined): RequestRoute | null;

/**
* Registers a server method where:
Expand Down
6 changes: 5 additions & 1 deletion test/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { expect } from '@hapi/code';
import {
Plugin,
Request,
RequestRoute,
ResponseToolkit,
Server,
ServerRoute,
Expand Down Expand Up @@ -77,7 +78,7 @@ const plugin: Plugin<TestPluginOptions, TestPluginDecorations> = {
register: function (srv: MyServer, options) {

check.type<TestPluginOptions>(options);

srv.expose({
add: function (a: number, b: number) {

Expand All @@ -89,6 +90,9 @@ const plugin: Plugin<TestPluginOptions, TestPluginDecorations> = {

const loadedServer = await server.register({ plugin, options: { x: 10 } });

check.type<RequestRoute | null>(server.match('GET', '/'));
check.type<RequestRoute | null>(server.match('get', '/'));

const sum = loadedServer.plugins.test.add(1, 2);
expect(sum).to.equal(130);
check.type<number>(sum);

0 comments on commit afb15c1

Please sign in to comment.