Skip to content

Commit

Permalink
fix: 🐛 loosen pre typings to allow for better programability
Browse files Browse the repository at this point in the history
  • Loading branch information
Danilo Alonso authored and Danilo Alonso committed Mar 15, 2024
1 parent 5ded9f7 commit e0e9685
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
4 changes: 2 additions & 2 deletions lib/types/route.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -339,12 +339,12 @@ export interface RouteOptionsPayload {
/**
* For context [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-routeoptionspre)
*/
export type RouteOptionsPreArray<Refs extends ReqRef = ReqRefDefaults> = RouteOptionsPreAllOptions<Refs>[];
export type RouteOptionsPreArray = RouteOptionsPreAllOptions[];

/**
* For context [See docs](https://github.com/hapijs/hapi/blob/master/API.md#-routeoptionspre)
*/
export type RouteOptionsPreAllOptions<Refs extends ReqRef = ReqRefDefaults> = RouteOptionsPreObject<Refs> | RouteOptionsPreObject<Refs>[] | Lifecycle.Method<Refs>;
export type RouteOptionsPreAllOptions = RouteOptionsPreObject<any> | RouteOptionsPreObject<any>[] | Lifecycle.Method<any>;

/**
* An object with:
Expand Down
12 changes: 10 additions & 2 deletions test/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,16 +100,24 @@ const typedHandler: Lifecycle.Method<{ Payload: { q: string; p: string } }> = (r
return new URLSearchParams(request.payload).toString();
};

const typedPre: Lifecycle.Method<{ Payload: { q: string } }> = (request, h) => {
const typedPre: Lifecycle.Method<{ Payload: { q: string; } }> = (request, h) => {

return h.continue;
};

const untypePre: Lifecycle.Method = (request, h) => {

return h.continue;
}

const typedRoute = {
method: 'POST',
path: '/',
options: {
handler: typedHandler,
pre: [typedPre]
pre: [
typedPre,
untypePre
]
}
} satisfies ServerRoute;

0 comments on commit e0e9685

Please sign in to comment.